[1810613] | 1 | import os |
---|
| 2 | import subprocess |
---|
| 3 | import re |
---|
[08dcf6c8] | 4 | import sys |
---|
[849fa92] | 5 | try: |
---|
| 6 | import xmlrunner |
---|
| 7 | except: |
---|
| 8 | print "xmlrunner needs to be installed to run these tests" |
---|
[c04af1b] | 9 | print "Try easy_install unittest-xml-reporting" |
---|
[bbd97e5] | 10 | sys.exit(1) |
---|
[1810613] | 11 | |
---|
[e89bb46] | 12 | # Check whether we have matplotlib installed |
---|
[aa01d07b] | 13 | HAS_MPL_WX = True |
---|
[e89bb46] | 14 | try: |
---|
| 15 | import matplotlib |
---|
[aa01d07b] | 16 | import wx |
---|
[e89bb46] | 17 | except: |
---|
[aa01d07b] | 18 | HAS_MPL_WX = False |
---|
[e89bb46] | 19 | |
---|
[61f557b] | 20 | SKIPPED_DIRS = ["sansrealspace", "calculatorview"] |
---|
[aa01d07b] | 21 | if not HAS_MPL_WX: |
---|
[e89bb46] | 22 | SKIPPED_DIRS.append("sansguiframe") |
---|
| 23 | |
---|
[bbd97e5] | 24 | #COMMAND_SEP = ';' |
---|
| 25 | #if os.name == 'nt': |
---|
| 26 | # COMMAND_SEP = '&' |
---|
[1810613] | 27 | |
---|
[6c00702] | 28 | def run_tests(dirs=None, all=False): |
---|
[bbd97e5] | 29 | test_root = os.path.abspath(os.path.dirname(__file__)) |
---|
| 30 | run_one_py = os.path.join(test_root, 'run_one.py') |
---|
[1810613] | 31 | passed = 0 |
---|
| 32 | failed = 0 |
---|
| 33 | n_tests = 0 |
---|
| 34 | n_errors = 0 |
---|
| 35 | n_failures = 0 |
---|
| 36 | |
---|
[6c00702] | 37 | for d in (dirs if dirs else os.listdir(test_root)): |
---|
[1810613] | 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 |
---|
[bbd97e5] | 44 | module_dir = os.path.join(test_root, d, "test") |
---|
[1810613] | 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) |
---|
[bbd97e5] | 50 | code = '"%s" %s %s'%(sys.executable, run_one_py, file_path) |
---|
[1810613] | 51 | proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) |
---|
| 52 | std_out, std_err = proc.communicate() |
---|
[bbd97e5] | 53 | #print std_out |
---|
| 54 | #sys.exit() |
---|
[6232a6f] | 55 | has_failed = True |
---|
[117a1d6] | 56 | m = re.search("Ran ([0-9]+) test", std_out) |
---|
[1810613] | 57 | if m is not None: |
---|
[6232a6f] | 58 | has_failed = False |
---|
[1810613] | 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 |
---|
[117a1d6] | 73 | print "Result for %s (%s): FAILED" % (module_name, module_dir) |
---|
[1810613] | 74 | print std_out |
---|
| 75 | else: |
---|
| 76 | passed += 1 |
---|
| 77 | print "Result for %s: SUCCESS" % module_name |
---|
[6c00702] | 78 | |
---|
[1810613] | 79 | print "\n----------------------------------------------" |
---|
[6c00702] | 80 | if n_tests == 0: |
---|
| 81 | print "No tests." |
---|
| 82 | else: |
---|
| 83 | print "Results by test modules:" |
---|
| 84 | print " PASSED: %d" % passed |
---|
| 85 | ratio = 100.0*failed/(failed+passed) |
---|
| 86 | print " FAILED: %d (%.0f%%)" % (failed,ratio) |
---|
| 87 | |
---|
| 88 | print "Results by tests:" |
---|
| 89 | print " Tests run: %d" % n_tests |
---|
| 90 | print " Tests failed: %d" % n_failures |
---|
| 91 | print " Test errors: %d" % n_errors |
---|
[1810613] | 92 | print "----------------------------------------------" |
---|
| 93 | |
---|
[d7b49576] | 94 | return failed |
---|
[1810613] | 95 | |
---|
| 96 | if __name__ == '__main__': |
---|
[6c00702] | 97 | all = (len(sys.argv) > 1 and sys.argv[1] == '-all') |
---|
| 98 | dirs = sys.argv[1:] if not all else sys.argv[2:] |
---|
| 99 | if run_tests(dirs=dirs, all=all)>0: |
---|
[d7b49576] | 100 | sys.exit(1) |
---|
| 101 | |
---|