source: inundation/ga/storm_surge/pyvolution/test_all.py @ 643

Last change on this file since 643 was 474, checked in by ole, 20 years ago

Added test_sparse.py unit test of sparse.py

File size: 1.5 KB
Line 
1"""Regression testing framework
2This module will search for scripts in the same directory named
3test_*.py.  Each such script should be a test suite that tests a
4module through PyUnit. This script will aggregate all
5found 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
11import unittest
12import 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#exclude = ['test_cg_solve.py']
20
21
22
23def regressionTest():
24    import sys, os, re, unittest   
25    path = os.path.split(sys.argv[0])[0] or os.getcwd()
26    files = os.listdir(path)
27    test = re.compile('^test_[\w]*.py$', re.IGNORECASE)
28    files = filter(test.search, files)
29
30    try:
31        files.remove(__file__)  #Remove self from list (Ver 2.3. or later)
32    except:
33        files.remove('test_all.py') 
34
35
36    if globals().has_key('exclude'):   
37        for file in exclude:
38            files.remove(file)
39            print 'WARNING: File '+ file + ' excluded from testing'
40       
41
42    filenameToModuleName = lambda f: os.path.splitext(f)[0]
43    moduleNames = map(filenameToModuleName, files)
44    modules = map(__import__, moduleNames)
45    load = unittest.defaultTestLoader.loadTestsFromModule
46    return unittest.TestSuite(map(load, modules))
47
48if __name__ == '__main__':
49
50    os.system('python compile.py') #Attempt to compile all extensions
51   
52    unittest.main(defaultTest='regressionTest')
53   
Note: See TracBrowser for help on using the repository browser.