source: sasview/test/utest_sasview.py @ 4fb10e5

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 4fb10e5 was ebb0a55, checked in by Ricardo Ferraz Leal <ricleal@…>, 7 years ago

Log for tests working now

  • Property mode set to 100644
File size: 3.7 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')
10print LOGGER_CONFIG_FILE
11logging.config.fileConfig(LOGGER_CONFIG_FILE)
12logger = logging.getLogger(__name__)
13
14try:
15    import xmlrunner
16except:
17    logger.error("xmlrunner needs to be installed to run these tests")
18    logger.error("Try easy_install unittest-xml-reporting")
19    sys.exit(1)
20
21# Check whether we have matplotlib installed
22HAS_MPL_WX = True
23try:
24    import matplotlib
25    import wx
26except:
27    HAS_MPL_WX = False
28
29SKIPPED_DIRS = ["sasrealspace", "calculatorview"]
30if not HAS_MPL_WX:
31    SKIPPED_DIRS.append("sasguiframe")
32
33#COMMAND_SEP = ';'
34#if os.name == 'nt':
35#    COMMAND_SEP = '&'
36
37def run_tests(dirs=None, all=False):
38    test_root = os.path.abspath(os.path.dirname(__file__))
39    run_one_py = os.path.join(test_root, 'run_one.py')
40    passed = 0
41    failed = 0
42    n_tests = 0
43    n_errors = 0
44    n_failures = 0
45   
46    for d in (dirs if dirs else os.listdir(test_root)):
47       
48        # Check for modules to be skipped
49        if d in SKIPPED_DIRS:
50            continue
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.