|
a/AlluraTesting/alluratest/test_syntax.py |
|
b/AlluraTesting/alluratest/test_syntax.py |
|
... |
|
... |
7 |
|
7 |
|
8 |
def run(cmd):
|
8 |
def run(cmd):
|
9 |
proc = Popen(cmd, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
|
9 |
proc = Popen(cmd, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
|
10 |
# must capture & reprint stdount, so that nosetests can capture it
|
10 |
# must capture & reprint stdount, so that nosetests can capture it
|
11 |
(stdout, stderr) = proc.communicate()
|
11 |
(stdout, stderr) = proc.communicate()
|
12 |
print stdout,
|
12 |
sys.stdout.write(stdout)
|
13 |
print >>sys.stderr, stderr,
|
13 |
sys.stderr.write(stderr)
|
14 |
return proc.returncode
|
14 |
return proc.returncode
|
15 |
|
15 |
|
16 |
find_py = "find Allura Forge* -name '*.py'"
|
16 |
find_py = "find Allura Forge* -name '*.py'"
|
|
|
17 |
|
|
|
18 |
# a recepe from itertools doc
|
|
|
19 |
from itertools import izip_longest
|
|
|
20 |
def grouper(n, iterable, fillvalue=None):
|
|
|
21 |
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
|
|
|
22 |
args = [iter(iterable)] * n
|
|
|
23 |
return izip_longest(fillvalue=fillvalue, *args)
|
17 |
|
24 |
|
18 |
def test_pyflakes():
|
25 |
def test_pyflakes():
|
19 |
# skip some that aren't critical errors
|
26 |
# skip some that aren't critical errors
|
20 |
skips = [
|
27 |
skips = [
|
21 |
'imported but unused',
|
28 |
'imported but unused',
|
22 |
'redefinition of unused',
|
29 |
'redefinition of unused',
|
23 |
'assigned to but never used',
|
30 |
'assigned to but never used',
|
24 |
]
|
31 |
]
|
25 |
cmd = find_py + " | grep -v '/migrations/' | xargs pyflakes"
|
32 |
proc = Popen(find_py, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
|
26 |
print 'Not skipping anything via grep:'
|
33 |
(find_stdout, stderr) = proc.communicate()
|
27 |
print cmd
|
34 |
sys.stderr.write(stderr)
|
28 |
print
|
35 |
assert proc.returncode == 0, proc.returncode
|
29 |
run(cmd)
|
|
|
30 |
|
36 |
|
31 |
print
|
37 |
# run pyflakes in batches, so it doesn't take tons of memory
|
32 |
print 'Skipping some stuff via grep:'
|
38 |
error = False
|
|
|
39 |
all_files = [f for f in find_stdout.split('\n')
|
|
|
40 |
if '/migrations/' not in f]
|
|
|
41 |
for files in grouper(20, all_files, fillvalue=''):
|
33 |
cmd += " | grep -v '" + "' | grep -v '".join(skips) + "'"
|
42 |
cmd = "pyflakes " + ' '.join(files) + " | grep -v '" + "' | grep -v '".join(skips) + "'"
|
34 |
print cmd
|
43 |
retval = run(cmd)
|
35 |
print
|
44 |
if retval != 1:
|
|
|
45 |
print
|
|
|
46 |
print 'Command was: %s' % cmd
|
|
|
47 |
print 'Returned %s' % retval
|
|
|
48 |
error = True
|
36 |
|
49 |
|
37 |
retval = run(cmd)
|
50 |
if error:
|
38 |
if retval != 1:
|
|
|
39 |
raise Exception('pyflakes failure, returned %s' % retval)
|
51 |
raise Exception('pyflakes failure, see stdout')
|
40 |
|
52 |
|
41 |
def test_no_now():
|
53 |
def test_no_now():
|
42 |
if run(find_py + " | xargs grep '\.now(' ") not in [1,123]:
|
54 |
if run(find_py + " | xargs grep '\.now(' ") not in [1,123]:
|
43 |
raise Exception("These should use .utcnow()")
|
55 |
raise Exception("These should use .utcnow()")
|
44 |
if run(find_py + " | xargs grep '\.fromtimestamp(' ") not in [1,123]:
|
56 |
if run(find_py + " | xargs grep '\.fromtimestamp(' ") not in [1,123]:
|