source: inundation/test_all.py @ 3422

Last change on this file since 3422 was 3422, checked in by duncan, 19 years ago

this test is ok now.

File size: 3.0 KB
Line 
1"""Regression testing framework
2This module will search for scripts in the same directory named
3test_*.py.  Each such script should be a test suite that tests a
4module through PyUnit. This script will aggregate all
5found test suites into one big test suite and run them all at once.
6"""
7
8# Author: Mark Pilgrim
9# Modified by Ole Nielsen
10
11import unittest
12import os
13import sys
14
15
16#List files that should be excluded from the testing process.
17#E.g. if they are known to fail and under development
18exclude_files = ['test_metis.py', 'test_version.py', 'test_parallel_sw.py',
19                 'test_advection.py', # removing this test for a bit
20                 ]
21                 #'test_calculate_region.py', 'test_calculate_point.py']
22                 #'test_init.py']
23
24exclude_dirs = ['pypar_dist', #Special requirements
25                'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn
26                'tmp']
27
28
29print "The following directories will be skipped over;"
30for dir in exclude_dirs:
31    print dir
32print ""
33
34def get_test_files(path):
35
36
37    try:
38        files = os.listdir(path)
39    except:
40        return []
41
42    #Check sub directories
43    test_files = []
44
45    #Exclude svn admin dirs
46    files = [x for x in files if x not in exclude_dirs]
47    path_files = []
48    for file in files:
49
50        absolute_filename = path + os.sep + file
51
52        #sys.path.append('pmesh')
53        if os.path.isdir(absolute_filename):
54            sys.path.append(file) #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems
55            path_files.append(file)
56            print 'Recursing into', file
57            more_test_files, more_path_files =get_test_files(absolute_filename)
58            test_files += more_test_files
59            path_files += more_path_files
60        elif file.startswith('test_') and file.endswith('.py'):
61            test_files.append(file)
62        else:
63            pass
64    return test_files , path_files
65
66
67
68def regressionTest():
69    path = os.getcwd()
70    test_files, path_files = get_test_files(path)
71    files = [x for x in test_files if not x == 'test_all.py']
72
73    print 'Testing path %s:' %('...'+path[-50:])
74    for file in files:
75        print '  ' + file
76    if globals().has_key('exclude_files'):
77        for file in exclude_files:
78            files.remove(file)
79            print 'WARNING: File '+ file + ' excluded from testing'
80
81    filenameToModuleName = lambda f: os.path.splitext(f)[0]
82    moduleNames = map(filenameToModuleName, files)
83    modules = map(__import__, moduleNames)
84
85    # Fix up the system path
86    for file in path_files:
87        sys.path.remove(file)
88       
89    load = unittest.defaultTestLoader.loadTestsFromModule
90    return unittest.TestSuite(map(load, modules))
91
92if __name__ == '__main__':
93    #unittest.main(defaultTest='regressionTest')
94
95    suite = regressionTest()
96    runner = unittest.TextTestRunner() #verbosity=2
97    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.