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 | |
---|
14 | |
---|
15 | #List files that should be excluded from the testing process. |
---|
16 | #E.g. if they are known to fail and under development |
---|
17 | exclude_files = ['test_metis.py', 'test_version.py', |
---|
18 | 'test_interpolate.py',# this is under development |
---|
19 | ] |
---|
20 | #'test_calculate_region.py', 'test_calculate_point.py'] |
---|
21 | #'test_init.py'] |
---|
22 | |
---|
23 | exclude_dirs = ['pypar_dist', #Special requirements |
---|
24 | 'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn |
---|
25 | 'tmp'] |
---|
26 | #'pmesh'] #Name conflict on my home machine (Ole) |
---|
27 | |
---|
28 | |
---|
29 | def get_test_files(path): |
---|
30 | |
---|
31 | import sys |
---|
32 | |
---|
33 | try: |
---|
34 | files = os.listdir(path) |
---|
35 | except: |
---|
36 | return [] |
---|
37 | |
---|
38 | #Check sub directories |
---|
39 | test_files = [] |
---|
40 | for file in files: |
---|
41 | |
---|
42 | #Exclude svn admin dirs |
---|
43 | if file in exclude_dirs: continue |
---|
44 | |
---|
45 | absolute_filename = path + os.sep + file |
---|
46 | |
---|
47 | if os.path.isdir(absolute_filename): |
---|
48 | sys.path.append(file) #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems |
---|
49 | print 'Recursing into', file |
---|
50 | test_files += get_test_files(absolute_filename) |
---|
51 | elif file.startswith('test_') and file.endswith('.py'): |
---|
52 | test_files.append(file) |
---|
53 | else: |
---|
54 | pass |
---|
55 | return test_files |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | def regressionTest(): |
---|
60 | import os, unittest |
---|
61 | path = os.getcwd() |
---|
62 | |
---|
63 | files = [x for x in get_test_files(path) if not x == 'test_all.py'] |
---|
64 | |
---|
65 | print 'Testing path %s:' %('...'+path[-50:]) |
---|
66 | for file in files: |
---|
67 | print ' ' + file |
---|
68 | |
---|
69 | if globals().has_key('exclude_files'): |
---|
70 | for file in exclude_files: |
---|
71 | files.remove(file) |
---|
72 | print 'WARNING: File '+ file + ' excluded from testing' |
---|
73 | |
---|
74 | |
---|
75 | filenameToModuleName = lambda f: os.path.splitext(f)[0] |
---|
76 | moduleNames = map(filenameToModuleName, files) |
---|
77 | modules = map(__import__, moduleNames) |
---|
78 | load = unittest.defaultTestLoader.loadTestsFromModule |
---|
79 | return unittest.TestSuite(map(load, modules)) |
---|
80 | |
---|
81 | if __name__ == '__main__': |
---|
82 | unittest.main(defaultTest='regressionTest') |
---|