source: sasview/test/utest_sasview.py @ f344f6c

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f344f6c was 959eb01, checked in by ajj, 7 years ago

normalising line endings

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