source: sasview/test/utest_sansview.py @ d7b49576

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 d7b49576 was d7b49576, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Trying to make running of system tests on build server catch errors

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