source: sasview/test/utest_sansview.py @ 08dcf6c8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 08dcf6c8 was 08dcf6c8, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Re #5 fixing mac tests

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