forked from emailage/Emailage_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscent.py
98 lines (68 loc) · 2.02 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
# -*- coding: utf-8 -*-
"""Configuration file for sniffer."""
import os
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 = ["emailage", "tests"]
@select_runnable('python')
@file_validator
def python_files(filename):
"""Match Python source files."""
return all(
(filename.endswith('.py'),
not os.path.basename(filename).startswith('.')),
)
@runnable
def python(*_):
"""Run targets for Python."""
for count, (command, title, retry) in enumerate((
(('make', 'test'), "Unit Tests", True),
(('make', 'tests'), "Integration Tests", False),
(('make', 'check'), "Static Analysis", True),
(('make', 'doc'), None, True),
), start=1):
if not run(command, title, count, retry):
return False
return True
GROUP = int(time.time()) # unique per run
_show_coverage = False
_rerun_args = None
def run(command, title, count, retry):
"""Run a command-line program and display the result."""
global _rerun_args
if _rerun_args:
args = _rerun_args
_rerun_args = None
if not run(*args):
return False
print("")
print("$ %s" % ' '.join(command))
failure = subprocess.call(command)
if failure:
mark = "❌" * count
message = mark + " [FAIL] " + mark
else:
mark = "✅" * count
message = mark + " [PASS] " + mark
show_notification(message, title)
show_coverage()
if failure and retry:
_rerun_args = command, title, count, retry
return not failure
def show_notification(message, title):
"""Show a user notification."""
if notify and title:
notify(message, title=title, group=GROUP)
def show_coverage():
"""Launch the coverage report."""
global _show_coverage
if _show_coverage:
subprocess.call(['make', 'read-coverage'])
_show_coverage = False