source: sasview/test/utest_sasview.py @ f80b416e

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f80b416e was be51cf6, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

fix corfunc tests

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