-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscent.py
115 lines (84 loc) · 2.47 KB
/
scent.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Configuration file for sniffer."""
import time
import subprocess
from sniffer.api import select_runnable, file_validator, runnable
try:
from pync import Notifier
except ImportError:
notify = None
else:
notify = Notifier.notify
watch_paths = [
"ballotbuddies",
"config",
"templates",
"tests",
]
class options:
group = int(time.time())
rerun_args = None
initial_run = True
@classmethod
def skip(cls):
should_skip = cls.initial_run
cls.initial_run = False
return should_skip
@select_runnable("backend_targets")
@file_validator
def backend_files(path):
return matches(path, "py", "ini", "html") and "system" not in path
@select_runnable("system_targets")
@file_validator
def system_files(path):
return matches(path, "py", "ini") and "system" in path
def matches(path, *extensions):
extension = path.split(".")[-1]
return extension in extensions
@runnable
def backend_targets(*_args):
return run(
"Backend",
[
("Unit Tests", "make test-backend-unit DISABLE_COVERAGE=true", True),
("Integration Tests", "make test-backend-all", False),
("Static Analysis", "make check-backend", True),
],
)
@runnable
def system_targets(*_args):
if options.skip():
return True
return run(
"System",
[
("Tests", "make test-system TEST_HEADLESS=true", False),
("Static Analysis", "make check-backend", True),
],
)
def run(name, targets):
count = 0
for count, (title, command, retry) in enumerate(targets, start=1):
success = call(f"{name} {title}", command, retry)
if not success:
message = "✅ " * (count - 1) + "❌"
show_notification(message, f"{name} {title}")
return False
message = "✅ " * count
title = f"All {name} Targets"
show_notification(message, title)
return True
def call(title, command, retry):
if options.rerun_args:
title, command, retry = options.rerun_args
options.rerun_args = None
success = call(title, command, retry)
if not success:
return False
print(f"\n\n$ {command}")
failure = subprocess.call(command, shell=True)
if failure and retry:
options.rerun_args = title, command, retry
return not failure
def show_notification(message, title):
if notify and title:
notify(message, title=title, group=options.group)