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
RevLine 
[6fe5100]1#!/usr/bin/env python
[1810613]2import os
3import subprocess
4import re
[08dcf6c8]5import sys
[849fa92]6try:
7    import xmlrunner
8except:
9    print "xmlrunner needs to be installed to run these tests"
[c04af1b]10    print "Try easy_install unittest-xml-reporting"
[bbd97e5]11    sys.exit(1)
[1810613]12
[e89bb46]13# Check whether we have matplotlib installed
[aa01d07b]14HAS_MPL_WX = True
[e89bb46]15try:
16    import matplotlib
[aa01d07b]17    import wx
[e89bb46]18except:
[aa01d07b]19    HAS_MPL_WX = False
[e89bb46]20
[61f557b]21SKIPPED_DIRS = ["sansrealspace", "calculatorview"]
[aa01d07b]22if not HAS_MPL_WX:
[e89bb46]23    SKIPPED_DIRS.append("sansguiframe")
24
[bbd97e5]25#COMMAND_SEP = ';'
26#if os.name == 'nt':
27#    COMMAND_SEP = '&'
[1810613]28
[6c00702]29def run_tests(dirs=None, all=False):
[bbd97e5]30    test_root = os.path.abspath(os.path.dirname(__file__))
31    run_one_py = os.path.join(test_root, 'run_one.py')
[1810613]32    passed = 0
33    failed = 0
34    n_tests = 0
35    n_errors = 0
36    n_failures = 0
37   
[6c00702]38    for d in (dirs if dirs else os.listdir(test_root)):
[1810613]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
[bbd97e5]45        module_dir = os.path.join(test_root, d, "test")
[1810613]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)
[bbd97e5]51                    code = '"%s" %s %s'%(sys.executable, run_one_py, file_path)
[1810613]52                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
53                    std_out, std_err = proc.communicate()
[bbd97e5]54                    #print std_out
55                    #sys.exit()
[6232a6f]56                    has_failed = True
[117a1d6]57                    m = re.search("Ran ([0-9]+) test", std_out)
[1810613]58                    if m is not None:
[6232a6f]59                        has_failed = False
[1810613]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
[117a1d6]74                        print "Result for %s (%s): FAILED" % (module_name, module_dir)
[1810613]75                        print std_out
76                    else:
77                        passed += 1
78                        print "Result for %s: SUCCESS" % module_name
[6c00702]79
[1810613]80    print "\n----------------------------------------------"
[6c00702]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
[1810613]93    print "----------------------------------------------"
94   
[d7b49576]95    return failed
[1810613]96
97if __name__ == '__main__':
[6c00702]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:
[d7b49576]101        sys.exit(1)
102   
Note: See TracBrowser for help on using the repository browser.