source: sasview/test/utest_sansview.py @ 0b11a4c

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 0b11a4c was 0b11a4c, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Re #5 fixing unit tests on windows

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[1810613]1import os
2import subprocess
3import re
4
[61f557b]5SKIPPED_DIRS = ["sansrealspace", "calculatorview"]
[295ddf5]6SANSVIEW_DIR = os.pardir
[1810613]7
8def run_tests():
9    passed = 0
10    failed = 0
11    n_tests = 0
12    n_errors = 0
13    n_failures = 0
14   
15    for d in os.listdir(SANSVIEW_DIR):
16       
17        # Check for modules to be skipped
18        if d in SKIPPED_DIRS:
19            continue
20       
21        # Go through modules looking for unit tests
[295ddf5]22        module_dir = os.path.join(os.getcwd(),SANSVIEW_DIR,d,"test")
[1810613]23        if os.path.isdir(module_dir):
24            for f in os.listdir(module_dir):
25                file_path = os.path.join(module_dir,f)
26                if os.path.isfile(file_path) and f.startswith("utest_") and f.endswith(".py"):
27                    module_name,_ = os.path.splitext(f)
[ea6e8b6]28                    code = "cd %s;python -c \"import sys;import xmlrunner;import unittest;sys.path.insert(0, '%s');" % (module_dir, module_dir)
[1810613]29                    code += "from %s import *;" % module_name
[6232a6f]30                    code += "unittest.main(testRunner=xmlrunner.XMLTestRunner(output='logs'))\""
[1810613]31                    proc = subprocess.Popen(code, shell=True, stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
32                    std_out, std_err = proc.communicate()
[6232a6f]33                    has_failed = True
[117a1d6]34                    m = re.search("Ran ([0-9]+) test", std_out)
[1810613]35                    if m is not None:
[6232a6f]36                        has_failed = False
[1810613]37                        n_tests += int(m.group(1))
38
39                    m = re.search("FAILED \(errors=([0-9]+)\)", std_out)
40                    if m is not None:
41                        has_failed = True
42                        n_errors += int(m.group(1))
43                   
44                    m = re.search("FAILED \(failures=([0-9]+)\)", std_out)
45                    if m is not None:
46                        has_failed = True
47                        n_failures += int(m.group(1))
48                   
49                    if has_failed:
50                        failed += 1
[117a1d6]51                        print "Result for %s (%s): FAILED" % (module_name, module_dir)
[0b11a4c]52                        print code
[1810613]53                        print std_out
54                    else:
55                        passed += 1
56                        print "Result for %s: SUCCESS" % module_name
57                       
58    print "\n----------------------------------------------"
59    print "Results by test modules:"
60    print "    PASSED: %d" % passed
61    ratio = 100.0*failed/(failed+passed)
62    print "    FAILED: %d    (%2.2g%%)" % (failed,ratio) 
63   
64    print "Results by tests:"
65    print "    Tests run:    %d" % n_tests
66    print "    Tests failed: %d" % n_failures
67    print "    Test errors:  %d" % n_errors
68    print "----------------------------------------------"
69   
70
71if __name__ == '__main__':
72    run_tests()                   
Note: See TracBrowser for help on using the repository browser.