source: sasview/test/utest_sansview.py @ 849fa92

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

Re #7 Add comment

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