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