source: sasview/test/utest_sansview.py @ 6c00702

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 6c00702 was 6c00702, checked in by pkienzle, 10 years ago

correct fitting tests so that they run (though not yet automatically)

  • Property mode set to 100644
File size: 3.4 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    sys.exit(1)
11
12# Check whether we have matplotlib installed
13HAS_MPL_WX = True
14try:
15    import matplotlib
16    import wx
17except:
18    HAS_MPL_WX = False
19
20SKIPPED_DIRS = ["sansrealspace", "calculatorview"]
21if not HAS_MPL_WX:
22    SKIPPED_DIRS.append("sansguiframe")
23
24#COMMAND_SEP = ';'
25#if os.name == 'nt':
26#    COMMAND_SEP = '&'
27
28def run_tests(dirs=None, all=False):
29    test_root = os.path.abspath(os.path.dirname(__file__))
30    run_one_py = os.path.join(test_root, 'run_one.py')
31    passed = 0
32    failed = 0
33    n_tests = 0
34    n_errors = 0
35    n_failures = 0
36   
37    for d in (dirs if dirs else os.listdir(test_root)):
38       
39        # Check for modules to be skipped
40        if d in SKIPPED_DIRS:
41            continue
42       
43        # Go through modules looking for unit tests
44        module_dir = os.path.join(test_root, d, "test")
45        if os.path.isdir(module_dir):
46            for f in os.listdir(module_dir):
47                file_path = os.path.join(module_dir,f)
48                if os.path.isfile(file_path) and f.startswith("utest_") and f.endswith(".py"):
49                    module_name,_ = os.path.splitext(f)
50                    code = '"%s" %s %s'%(sys.executable, run_one_py, file_path)
51                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
52                    std_out, std_err = proc.communicate()
53                    #print std_out
54                    #sys.exit()
55                    has_failed = True
56                    m = re.search("Ran ([0-9]+) test", std_out)
57                    if m is not None:
58                        has_failed = False
59                        n_tests += int(m.group(1))
60
61                    m = re.search("FAILED \(errors=([0-9]+)\)", std_out)
62                    if m is not None:
63                        has_failed = True
64                        n_errors += int(m.group(1))
65                   
66                    m = re.search("FAILED \(failures=([0-9]+)\)", std_out)
67                    if m is not None:
68                        has_failed = True
69                        n_failures += int(m.group(1))
70                   
71                    if has_failed:
72                        failed += 1
73                        print "Result for %s (%s): FAILED" % (module_name, module_dir)
74                        print std_out
75                    else:
76                        passed += 1
77                        print "Result for %s: SUCCESS" % module_name
78
79    print "\n----------------------------------------------"
80    if n_tests == 0:
81        print "No tests."
82    else:
83        print "Results by test modules:"
84        print "    PASSED: %d" % passed
85        ratio = 100.0*failed/(failed+passed)
86        print "    FAILED: %d    (%.0f%%)" % (failed,ratio)
87
88        print "Results by tests:"
89        print "    Tests run:    %d" % n_tests
90        print "    Tests failed: %d" % n_failures
91        print "    Test errors:  %d" % n_errors
92    print "----------------------------------------------"
93   
94    return failed
95
96if __name__ == '__main__':
97    all = (len(sys.argv) > 1 and sys.argv[1] == '-all')
98    dirs = sys.argv[1:] if not all else sys.argv[2:]
99    if run_tests(dirs=dirs, all=all)>0:
100        sys.exit(1)
101   
Note: See TracBrowser for help on using the repository browser.