source: inundation/test_all.py @ 3354

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

removing a test in develpement

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