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_least_squares.py', 'test_cg_solve.py', |
---|
18 | 'test_interpolate_sww.py'] |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | def regressionTest(): |
---|
23 | import sys, os, re, unittest |
---|
24 | path = os.path.split(sys.argv[0])[0] or os.getcwd() |
---|
25 | files = os.listdir(path) |
---|
26 | test = re.compile('^test_[\w]*.py$', re.IGNORECASE) |
---|
27 | files = filter(test.search, files) |
---|
28 | |
---|
29 | try: |
---|
30 | files.remove(__file__) #Remove self from list (Ver 2.3. or later) |
---|
31 | except: |
---|
32 | files.remove('test_all.py') |
---|
33 | |
---|
34 | |
---|
35 | for file in exclude: |
---|
36 | files.remove(file) |
---|
37 | print 'WARNING: File '+ file + ' excluded from testing' |
---|
38 | |
---|
39 | |
---|
40 | filenameToModuleName = lambda f: os.path.splitext(f)[0] |
---|
41 | moduleNames = map(filenameToModuleName, files) |
---|
42 | modules = map(__import__, moduleNames) |
---|
43 | load = unittest.defaultTestLoader.loadTestsFromModule |
---|
44 | return unittest.TestSuite(map(load, modules)) |
---|
45 | |
---|
46 | if __name__ == '__main__': |
---|
47 | |
---|
48 | os.system('python compile.py') #Attempt to compile all extensions |
---|
49 | |
---|
50 | unittest.main(defaultTest='regressionTest') |
---|
51 | |
---|