source: sasview/test/utest_sansview.py @ 2a48bb0

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

Re #5 fixing unit tests on windows

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import os
2import subprocess
3import re
4
5SKIPPED_DIRS = ["sansrealspace", "calculatorview"]
6SANSVIEW_DIR = os.pardir
7COMMAND_SEP = ';'
8if os.name == 'nt':
9    COMMAND_SEP = '&'
10
11def 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
25        module_dir = os.path.join(os.getcwd(),SANSVIEW_DIR,d,"test")
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)
31                    code = "cd %s%spython -c \"import sys;import xmlrunner;import unittest;sys.path.insert(0, '%s');" % (module_dir, COMMAND_SEP, module_dir)
32                    code += "from %s import *;" % module_name
33                    code += "unittest.main(testRunner=xmlrunner.XMLTestRunner(output='logs'))\""
34                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
35                    std_out, std_err = proc.communicate()
36                    has_failed = True
37                    m = re.search("Ran ([0-9]+) test", std_out)
38                    if m is not None:
39                        has_failed = False
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
54                        print "Result for %s (%s): FAILED" % (module_name, module_dir)
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
73if __name__ == '__main__':
74    run_tests()                   
Note: See TracBrowser for help on using the repository browser.