source: sasview/test/utest_sansview.py @ 786685e

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

Bumps first pass. Fitting works but no pretty pictures

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