source: sasview/test/utest_sansview.py @ 295ddf5

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