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