Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert regexes of type str to list #831

Merged
merged 2 commits into from Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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