1 | import os |
---|
2 | import subprocess |
---|
3 | import re |
---|
4 | import sys |
---|
5 | try: |
---|
6 | import xmlrunner |
---|
7 | except: |
---|
8 | print "xmlrunner needs to be installed to run these tests" |
---|
9 | print "Try easy_install unittest-xml-reporting" |
---|
10 | sys.exit(1) |
---|
11 | |
---|
12 | # Check whether we have matplotlib installed |
---|
13 | HAS_MPL_WX = True |
---|
14 | try: |
---|
15 | import matplotlib |
---|
16 | import wx |
---|
17 | except: |
---|
18 | HAS_MPL_WX = False |
---|
19 | |
---|
20 | SKIPPED_DIRS = ["sansrealspace", "calculatorview"] |
---|
21 | if not HAS_MPL_WX: |
---|
22 | SKIPPED_DIRS.append("sansguiframe") |
---|
23 | |
---|
24 | #COMMAND_SEP = ';' |
---|
25 | #if os.name == 'nt': |
---|
26 | # COMMAND_SEP = '&' |
---|
27 | |
---|
28 | def run_tests(): |
---|
29 | test_root = os.path.abspath(os.path.dirname(__file__)) |
---|
30 | run_one_py = os.path.join(test_root, 'run_one.py') |
---|
31 | passed = 0 |
---|
32 | failed = 0 |
---|
33 | n_tests = 0 |
---|
34 | n_errors = 0 |
---|
35 | n_failures = 0 |
---|
36 | |
---|
37 | for d in os.listdir(test_root): |
---|
38 | |
---|
39 | # Check for modules to be skipped |
---|
40 | if d in SKIPPED_DIRS: |
---|
41 | continue |
---|
42 | |
---|
43 | # Go through modules looking for unit tests |
---|
44 | module_dir = os.path.join(test_root, d, "test") |
---|
45 | if os.path.isdir(module_dir): |
---|
46 | for f in os.listdir(module_dir): |
---|
47 | file_path = os.path.join(module_dir,f) |
---|
48 | if os.path.isfile(file_path) and f.startswith("utest_") and f.endswith(".py"): |
---|
49 | module_name,_ = os.path.splitext(f) |
---|
50 | code = '"%s" %s %s'%(sys.executable, run_one_py, file_path) |
---|
51 | proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) |
---|
52 | std_out, std_err = proc.communicate() |
---|
53 | #print std_out |
---|
54 | #sys.exit() |
---|
55 | has_failed = True |
---|
56 | m = re.search("Ran ([0-9]+) test", std_out) |
---|
57 | if m is not None: |
---|
58 | has_failed = False |
---|
59 | n_tests += int(m.group(1)) |
---|
60 | |
---|
61 | m = re.search("FAILED \(errors=([0-9]+)\)", std_out) |
---|
62 | if m is not None: |
---|
63 | has_failed = True |
---|
64 | n_errors += int(m.group(1)) |
---|
65 | |
---|
66 | m = re.search("FAILED \(failures=([0-9]+)\)", std_out) |
---|
67 | if m is not None: |
---|
68 | has_failed = True |
---|
69 | n_failures += int(m.group(1)) |
---|
70 | |
---|
71 | if has_failed: |
---|
72 | failed += 1 |
---|
73 | print "Result for %s (%s): FAILED" % (module_name, module_dir) |
---|
74 | print std_out |
---|
75 | else: |
---|
76 | passed += 1 |
---|
77 | print "Result for %s: SUCCESS" % module_name |
---|
78 | |
---|
79 | print "\n----------------------------------------------" |
---|
80 | print "Results by test modules:" |
---|
81 | print " PASSED: %d" % passed |
---|
82 | ratio = 100.0*failed/(failed+passed) |
---|
83 | print " FAILED: %d (%.0f%%)" % (failed,ratio) |
---|
84 | |
---|
85 | print "Results by tests:" |
---|
86 | print " Tests run: %d" % n_tests |
---|
87 | print " Tests failed: %d" % n_failures |
---|
88 | print " Test errors: %d" % n_errors |
---|
89 | print "----------------------------------------------" |
---|
90 | |
---|
91 | return failed |
---|
92 | |
---|
93 | if __name__ == '__main__': |
---|
94 | if run_tests()>0: |
---|
95 | sys.exit(1) |
---|
96 | |
---|