mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
closes #1828 script reloads on py file changes
This commit is contained in:
parent
d4264cb719
commit
809207195d
@ -110,11 +110,16 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler):
|
|||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
|
||||||
def filter(self, event):
|
def filter(self, event):
|
||||||
|
"""
|
||||||
|
Returns True only when .py file is changed
|
||||||
|
"""
|
||||||
if event.is_directory:
|
if event.is_directory:
|
||||||
return False
|
return False
|
||||||
if os.path.basename(event.src_path).startswith("."):
|
if os.path.basename(event.src_path).startswith("."):
|
||||||
return False
|
return False
|
||||||
|
if event.src_path.endswith(".py"):
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
if self.filter(event):
|
if self.filter(event):
|
||||||
|
@ -44,14 +44,19 @@ def test_reloadhandler():
|
|||||||
rh = script.ReloadHandler(Called())
|
rh = script.ReloadHandler(Called())
|
||||||
assert not rh.filter(watchdog.events.DirCreatedEvent("path"))
|
assert not rh.filter(watchdog.events.DirCreatedEvent("path"))
|
||||||
assert not rh.filter(watchdog.events.FileModifiedEvent("/foo/.bar"))
|
assert not rh.filter(watchdog.events.FileModifiedEvent("/foo/.bar"))
|
||||||
assert rh.filter(watchdog.events.FileModifiedEvent("/foo/bar"))
|
assert not rh.filter(watchdog.events.FileModifiedEvent("/foo/bar"))
|
||||||
|
assert rh.filter(watchdog.events.FileModifiedEvent("/foo/bar.py"))
|
||||||
|
|
||||||
assert not rh.callback.called
|
assert not rh.callback.called
|
||||||
rh.on_modified(watchdog.events.FileModifiedEvent("/foo/bar"))
|
rh.on_modified(watchdog.events.FileModifiedEvent("/foo/bar"))
|
||||||
|
assert not rh.callback.called
|
||||||
|
rh.on_modified(watchdog.events.FileModifiedEvent("/foo/bar.py"))
|
||||||
assert rh.callback.called
|
assert rh.callback.called
|
||||||
rh.callback.called = False
|
rh.callback.called = False
|
||||||
|
|
||||||
rh.on_created(watchdog.events.FileCreatedEvent("foo"))
|
rh.on_created(watchdog.events.FileCreatedEvent("foo"))
|
||||||
|
assert not rh.callback.called
|
||||||
|
rh.on_created(watchdog.events.FileCreatedEvent("foo.py"))
|
||||||
assert rh.callback.called
|
assert rh.callback.called
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user