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 = ['test_geo_reference.py','test_redfearn.py', 'test_point.py'] |
---|
18 | |
---|
19 | |
---|
20 | def get_test_files(path): |
---|
21 | |
---|
22 | import sys |
---|
23 | |
---|
24 | files = os.listdir(path) |
---|
25 | |
---|
26 | #Check sub directories |
---|
27 | test_files = [] |
---|
28 | for file in files: |
---|
29 | if os.path.isdir(file): |
---|
30 | sys.path.append(file) |
---|
31 | #print 'Recursing into', file |
---|
32 | test_files += get_test_files(path + os.sep + file) |
---|
33 | elif file[:5] == 'test_' and file[-2:] == 'py': |
---|
34 | #print 'Appending', file |
---|
35 | test_files.append(file) |
---|
36 | else: |
---|
37 | pass |
---|
38 | return test_files |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | def regressionTest(): |
---|
43 | import sys, os, re, unittest |
---|
44 | path = os.path.split(sys.argv[0])[0] or os.getcwd() |
---|
45 | |
---|
46 | |
---|
47 | files = get_test_files(path) |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | #test = re.compile('^test_[\w]*.py$', re.IGNORECASE) |
---|
52 | #files = filter(test.search, files) |
---|
53 | |
---|
54 | |
---|
55 | try: |
---|
56 | files.remove(__file__) #Remove self from list (Ver 2.3. or later) |
---|
57 | except: |
---|
58 | files.remove('test_all.py') |
---|
59 | |
---|
60 | print 'Testing:' |
---|
61 | for file in files: |
---|
62 | print ' ' + file |
---|
63 | |
---|
64 | if globals().has_key('exclude'): |
---|
65 | for file in exclude: |
---|
66 | files.remove(file) |
---|
67 | print 'WARNING: File '+ file + ' excluded from testing' |
---|
68 | |
---|
69 | |
---|
70 | filenameToModuleName = lambda f: os.path.splitext(f)[0] |
---|
71 | #print "files",files |
---|
72 | moduleNames = map(filenameToModuleName, files) |
---|
73 | #print "moduleNames",moduleNames |
---|
74 | modules = map(__import__, moduleNames) |
---|
75 | load = unittest.defaultTestLoader.loadTestsFromModule |
---|
76 | return unittest.TestSuite(map(load, modules)) |
---|
77 | |
---|
78 | ################################################################################ |
---|
79 | |
---|
80 | if __name__ == '__main__': |
---|
81 | from os import sep |
---|
82 | |
---|
83 | #Attempt to compile all extensions |
---|
84 | #execfile('..' + sep + 'utilities' + sep + 'compile.py') |
---|
85 | |
---|
86 | #FIXME: Temporary measure |
---|
87 | #os.chdir('..' + sep + 'utilities') |
---|
88 | #execfile('compile.py') |
---|
89 | #os.chdir('..' + sep + 'load_mesh') |
---|
90 | |
---|
91 | #FIXME: Temporary measure |
---|
92 | #os.chdir('..' + sep + 'triangle') |
---|
93 | #execfile('compile.py') |
---|
94 | #os.chdir('..' + sep + 'load_mesh') |
---|
95 | |
---|
96 | #os.system('python compile.py') |
---|
97 | |
---|
98 | #print regressionTest() |
---|
99 | unittest.main(defaultTest='regressionTest') |
---|