source: anuga_core/source/anuga/test_all.py @ 3546

Last change on this file since 3546 was 3470, checked in by ole, 19 years ago

Excluded test of the old least_squares module (now superseded by fit_interpolate.

File size: 3.1 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_version.py', 'test_least_squares.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            print 'WARNING: File '+ file + ' to be excluded from testing'
79            try:   
80                files.remove(file)
81            except ValueError, e:
82                msg = 'File "%s" was not found in test suite.\n' %file
83                msg += 'Original error is "%s"\n' %e
84                msg += 'Perhaps it should be removed from exclude list?' 
85                raise Exception, msg
86
87    filenameToModuleName = lambda f: os.path.splitext(f)[0]
88    moduleNames = map(filenameToModuleName, files)
89    modules = map(__import__, moduleNames)
90
91    # Fix up the system path
92    for file in path_files:
93        sys.path.remove(file)
94       
95    load = unittest.defaultTestLoader.loadTestsFromModule
96    return unittest.TestSuite(map(load, modules))
97
98if __name__ == '__main__':
99    #unittest.main(defaultTest='regressionTest')
100
101    suite = regressionTest()
102    runner = unittest.TextTestRunner() #verbosity=2
103    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.