Skip to content

Commit

Permalink
Convert regexes of type str to list (#831)
Browse files Browse the repository at this point in the history
* convert regexes of type str to list

* > tests added
> updated changelog.rst
  • Loading branch information
unique1o1 committed Aug 22, 2021
1 parent c74381c commit 75fe2d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions changelog.rst
Expand Up @@ -8,8 +8,8 @@ Changelog

2021-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.1.4...master>`__

-
- Thanks to our beloved contributors: @
- convert regexes of type str to list. (`#831 <https://github.com/gorakhargosh/watchdog/pull/831>`_)
- Thanks to our beloved contributors: @unique1o1

2.1.4
~~~~~
Expand Down
2 changes: 2 additions & 0 deletions src/watchdog/events.py
Expand Up @@ -418,6 +418,8 @@ def __init__(self, regexes=None, ignore_regexes=None,

if regexes is None:
regexes = [r".*"]
elif isinstance(regexes, str):
regexes = [regexes]
if ignore_regexes is None:
ignore_regexes = []
if case_sensitive:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_regex_matching_event_handler.py
Expand Up @@ -35,6 +35,7 @@
path_1 = '/path/xyz'
path_2 = '/path/abc'
g_allowed_regexes = [r".*\.py", r".*\.txt"]
g_allowed_str_regexes = r".*\.py"
g_ignore_regexes = [r".*\.pyc"]


Expand Down Expand Up @@ -186,6 +187,12 @@ def test_regexes():
assert [r.pattern for r in handler1.regexes] == g_allowed_regexes


def test_str_regexes():
handler1 = RegexMatchingEventHandler(g_allowed_str_regexes,
g_ignore_regexes, True)
assert [r.pattern for r in handler1.regexes] == [g_allowed_str_regexes]


def test_logging_event_handler_dispatch():

class _TestableEventHandler(LoggingEventHandler):
Expand Down

0 comments on commit 75fe2d2

Please sign in to comment.