1 | import os |
---|
2 | import subprocess |
---|
3 | import re |
---|
4 | |
---|
5 | SKIPPED_DIRS = ["sansrealspace"] |
---|
6 | SANSVIEW_DIR = ".." |
---|
7 | |
---|
8 | def run_tests(): |
---|
9 | passed = 0 |
---|
10 | failed = 0 |
---|
11 | n_tests = 0 |
---|
12 | n_errors = 0 |
---|
13 | n_failures = 0 |
---|
14 | |
---|
15 | for d in os.listdir(SANSVIEW_DIR): |
---|
16 | |
---|
17 | # Check for modules to be skipped |
---|
18 | if d in SKIPPED_DIRS: |
---|
19 | continue |
---|
20 | |
---|
21 | # Go through modules looking for unit tests |
---|
22 | module_dir = os.path.join(SANSVIEW_DIR,d,"test") |
---|
23 | if os.path.isdir(module_dir): |
---|
24 | for f in os.listdir(module_dir): |
---|
25 | file_path = os.path.join(module_dir,f) |
---|
26 | if os.path.isfile(file_path) and f.startswith("utest_") and f.endswith(".py"): |
---|
27 | module_name,_ = os.path.splitext(f) |
---|
28 | code = "cd %s;python -c \"import sys;import xmlrunner;import unittest;sys.path.insert(0, '%s');" % (module_dir, module_dir) |
---|
29 | code += "from %s import *;" % module_name |
---|
30 | code += "unittest.main(testRunner=xmlrunner.XMLTestRunner(output='logs'))\"" |
---|
31 | proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) |
---|
32 | std_out, std_err = proc.communicate() |
---|
33 | has_failed = True |
---|
34 | m = re.search("Ran ([0-9]+) tests", std_out) |
---|
35 | if m is not None: |
---|
36 | has_failed = False |
---|
37 | n_tests += int(m.group(1)) |
---|
38 | |
---|
39 | m = re.search("FAILED \(errors=([0-9]+)\)", std_out) |
---|
40 | if m is not None: |
---|
41 | has_failed = True |
---|
42 | n_errors += int(m.group(1)) |
---|
43 | |
---|
44 | m = re.search("FAILED \(failures=([0-9]+)\)", std_out) |
---|
45 | if m is not None: |
---|
46 | has_failed = True |
---|
47 | n_failures += int(m.group(1)) |
---|
48 | |
---|
49 | if has_failed: |
---|
50 | failed += 1 |
---|
51 | print "Result for %s: FAILED" % module_name |
---|
52 | print std_out |
---|
53 | else: |
---|
54 | passed += 1 |
---|
55 | print "Result for %s: SUCCESS" % module_name |
---|
56 | |
---|
57 | print "\n----------------------------------------------" |
---|
58 | print "Results by test modules:" |
---|
59 | print " PASSED: %d" % passed |
---|
60 | ratio = 100.0*failed/(failed+passed) |
---|
61 | print " FAILED: %d (%2.2g%%)" % (failed,ratio) |
---|
62 | |
---|
63 | print "Results by tests:" |
---|
64 | print " Tests run: %d" % n_tests |
---|
65 | print " Tests failed: %d" % n_failures |
---|
66 | print " Test errors: %d" % n_errors |
---|
67 | print "----------------------------------------------" |
---|
68 | |
---|
69 | |
---|
70 | if __name__ == '__main__': |
---|
71 | run_tests() |
---|