--- a/AlluraTesting/alluratest/test_syntax.py
+++ b/AlluraTesting/alluratest/test_syntax.py
@@ -9,11 +9,18 @@
proc = Popen(cmd, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
# must capture & reprint stdount, so that nosetests can capture it
(stdout, stderr) = proc.communicate()
- print stdout,
- print >>sys.stderr, stderr,
+ sys.stdout.write(stdout)
+ sys.stderr.write(stderr)
return proc.returncode
find_py = "find Allura Forge* -name '*.py'"
+
+# a recepe from itertools doc
+from itertools import izip_longest
+def grouper(n, iterable, fillvalue=None):
+ "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
+ args = [iter(iterable)] * n
+ return izip_longest(fillvalue=fillvalue, *args)
def test_pyflakes():
# skip some that aren't critical errors
@@ -22,21 +29,26 @@
'redefinition of unused',
'assigned to but never used',
]
- cmd = find_py + " | grep -v '/migrations/' | xargs pyflakes"
- print 'Not skipping anything via grep:'
- print cmd
- print
- run(cmd)
+ proc = Popen(find_py, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
+ (find_stdout, stderr) = proc.communicate()
+ sys.stderr.write(stderr)
+ assert proc.returncode == 0, proc.returncode
- print
- print 'Skipping some stuff via grep:'
- cmd += " | grep -v '" + "' | grep -v '".join(skips) + "'"
- print cmd
- print
+ # run pyflakes in batches, so it doesn't take tons of memory
+ error = False
+ all_files = [f for f in find_stdout.split('\n')
+ if '/migrations/' not in f]
+ for files in grouper(20, all_files, fillvalue=''):
+ cmd = "pyflakes " + ' '.join(files) + " | grep -v '" + "' | grep -v '".join(skips) + "'"
+ retval = run(cmd)
+ if retval != 1:
+ print
+ print 'Command was: %s' % cmd
+ print 'Returned %s' % retval
+ error = True
- retval = run(cmd)
- if retval != 1:
- raise Exception('pyflakes failure, returned %s' % retval)
+ if error:
+ raise Exception('pyflakes failure, see stdout')
def test_no_now():
if run(find_py + " | xargs grep '\.now(' ") not in [1,123]: