forked from dimagi/commcare-hq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scent.py
64 lines (50 loc) · 1.67 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
"""Usage:
sniffer -x --js-app_manager -x corehq.apps.app_manager:AppManagerViewTest
You can get sniffer to run both js and python tests. Set which js tests you want to run with `--js-{app_name}`
Use the nose syntax for python tests
When you save a .js file, the js tests run,
When you save a .py file, the python tests run.
"""
import os
from subprocess import Popen
from sniffer.api import runnable, select_runnable, file_validator
@select_runnable('python_tests')
@file_validator
def python_test_files(filename):
return (
(filename.endswith('.py') or
filename.endswith('.json') or
filename.endswith('.xml'))
and not os.path.basename(filename).startswith('.')
)
# Here we instruct the 'javascript_tests' runnable to be kicked off
# when a .js file is changed
@select_runnable('javascript_tests')
@file_validator
def js_files(filename):
return filename.endswith('.js') and not os.path.basename(filename).startswith('.')
def run_test(fn):
process = Popen(fn)
try:
return process.wait() == 0
except KeyboardInterrupt:
process.terminate()
raise
@runnable
def javascript_tests(*args):
fn = ['grunt']
args = args[1:]
tests_to_run = ["mocha:{}".format(arg.split('--js-')[1]) for arg in args if arg.startswith('--js-')]
if tests_to_run:
fn += tests_to_run
return run_test(fn)
return True
@runnable
def python_tests(*args):
fn = ['python', 'manage.py', 'test', '--noinput', '--settings=testsettings']
args = args[1:]
tests_to_run = [arg for arg in args if not arg.startswith('--js-')]
if tests_to_run:
fn += tests_to_run
return run_test(fn)
return True