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