forked from mmb/weechat-otr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_tests.py
38 lines (29 loc) · 1.03 KB
/
watch_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import subprocess
import time
import watchdog.observers
import watchdog.events
class CodeModifiedEventHandler(watchdog.events.PatternMatchingEventHandler):
def __init__(self, command):
super(CodeModifiedEventHandler, self).__init__(['*.py'])
self.command = command
def on_any_event(self, event):
try:
print(subprocess.check_output(self.command))
except subprocess.CalledProcessError as err:
print(err.output)
print('-' * 80)
class TestWatcher(object):
def __init__(self, path, command):
self.observer = watchdog.observers.Observer()
handler = CodeModifiedEventHandler(command)
self.observer.schedule(handler, path, recursive=True)
def start(self):
self.observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
self.observer.stop()
self.observer.join()
if __name__ == '__main__':
TestWatcher('.', ['python', '-m', 'unittest', 'discover']).start()