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

Last change on this file since 3742 was 3678, checked in by steve, 18 years ago

Added more limiting to cells near dry cells, use beta_*_dry

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
18
19exclude_files = []
20if sys.platform != 'win32':  #Windows
21    exclude_files.append('test_advection.py') #Weave doesn't work on Linux
22
23exclude_dirs = ['pypar_dist', #Special requirements
24                'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn
25                'tmp']
26
27
28print "The following directories will be skipped over;"
29for dir in exclude_dirs:
30    print dir
31print ""
32
33def get_test_files(path):
34
35
36    try:
37        files = os.listdir(path)
38    except:
39        return []
40
41    #Check sub directories
42    test_files = []
43
44    #Exclude svn admin dirs
45    files = [x for x in files if x not in exclude_dirs]
46    path_files = []
47    for file in files:
48
49        absolute_filename = path + os.sep + file
50
51        #sys.path.append('pmesh')
52        if os.path.isdir(absolute_filename):
53            sys.path.append(file) #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems
54            path_files.append(file)
55            print 'Recursing into', file
56            more_test_files, more_path_files =get_test_files(absolute_filename)
57            test_files += more_test_files
58            path_files += more_path_files
59        elif file.startswith('test_') and file.endswith('.py'):
60            test_files.append(file)
61        else:
62            pass
63    return test_files , path_files
64
65
66
67def regressionTest():
68    path = os.getcwd()
69    test_files, path_files = get_test_files(path)
70    files = [x for x in test_files if not x == 'test_all.py']
71
72    print 'Testing path %s:' %('...'+path[-50:])
73    for file in files:
74        print '  ' + file
75    if globals().has_key('exclude_files'):
76        for file in exclude_files:
77            print 'WARNING: File '+ file + ' to be excluded from testing'
78        try:   
79            files.remove(file)
80        except ValueError, e:
81            msg = 'File "%s" was not found in test suite.\n' %file
82            msg += 'Original error is "%s"\n' %e
83            msg += 'Perhaps it should be removed from exclude list?' 
84            raise Exception, msg
85
86    filenameToModuleName = lambda f: os.path.splitext(f)[0]
87    moduleNames = map(filenameToModuleName, files)
88    modules = map(__import__, moduleNames)
89
90    # Fix up the system path
91    for file in path_files:
92        sys.path.remove(file)
93       
94    load = unittest.defaultTestLoader.loadTestsFromModule
95    return unittest.TestSuite(map(load, modules))
96
97if __name__ == '__main__':
98    #unittest.main(defaultTest='regressionTest')
99
100    suite = regressionTest()
101    runner = unittest.TextTestRunner() #verbosity=2
102    runner.run(suite)
103   
Note: See TracBrowser for help on using the repository browser.