[2638] | 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 |
---|
[2762] | 13 | import sys |
---|
[2638] | 14 | |
---|
| 15 | |
---|
| 16 | #List files that should be excluded from the testing process. |
---|
| 17 | #E.g. if they are known to fail and under development |
---|
[2750] | 18 | exclude_files = ['test_metis.py', 'test_version.py', 'test_parallel_sw.py', |
---|
[3052] | 19 | 'test_advection.py', # removing this test for a bit |
---|
[3097] | 20 | #'test_mesh.py', # bug fixing |
---|
[2638] | 21 | ] |
---|
| 22 | #'test_calculate_region.py', 'test_calculate_point.py'] |
---|
| 23 | #'test_init.py'] |
---|
| 24 | |
---|
| 25 | exclude_dirs = ['pypar_dist', #Special requirements |
---|
| 26 | 'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn |
---|
[2744] | 27 | 'tmp'] |
---|
[2638] | 28 | |
---|
| 29 | |
---|
[2744] | 30 | print "The following directories will be skipped over;" |
---|
| 31 | for dir in exclude_dirs: |
---|
| 32 | print dir |
---|
| 33 | print "" |
---|
| 34 | |
---|
[2638] | 35 | def get_test_files(path): |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | try: |
---|
| 39 | files = os.listdir(path) |
---|
| 40 | except: |
---|
| 41 | return [] |
---|
| 42 | |
---|
| 43 | #Check sub directories |
---|
| 44 | test_files = [] |
---|
[2744] | 45 | |
---|
[2762] | 46 | #Exclude svn admin dirs |
---|
| 47 | files = [x for x in files if x not in exclude_dirs] |
---|
| 48 | path_files = [] |
---|
[2638] | 49 | for file in files: |
---|
| 50 | |
---|
| 51 | absolute_filename = path + os.sep + file |
---|
| 52 | |
---|
[2762] | 53 | #sys.path.append('pmesh') |
---|
[2638] | 54 | if os.path.isdir(absolute_filename): |
---|
| 55 | sys.path.append(file) #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems |
---|
[2762] | 56 | path_files.append(file) |
---|
[2638] | 57 | print 'Recursing into', file |
---|
[2762] | 58 | more_test_files, more_path_files =get_test_files(absolute_filename) |
---|
| 59 | test_files += more_test_files |
---|
| 60 | path_files += more_path_files |
---|
[2638] | 61 | elif file.startswith('test_') and file.endswith('.py'): |
---|
| 62 | test_files.append(file) |
---|
| 63 | else: |
---|
| 64 | pass |
---|
[2762] | 65 | return test_files , path_files |
---|
[2638] | 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | def regressionTest(): |
---|
| 70 | path = os.getcwd() |
---|
[2762] | 71 | test_files, path_files = get_test_files(path) |
---|
| 72 | files = [x for x in test_files if not x == 'test_all.py'] |
---|
[2638] | 73 | |
---|
| 74 | print 'Testing path %s:' %('...'+path[-50:]) |
---|
| 75 | for file in files: |
---|
| 76 | print ' ' + file |
---|
| 77 | if globals().has_key('exclude_files'): |
---|
| 78 | for file in exclude_files: |
---|
| 79 | files.remove(file) |
---|
| 80 | print 'WARNING: File '+ file + ' excluded from testing' |
---|
| 81 | |
---|
| 82 | filenameToModuleName = lambda f: os.path.splitext(f)[0] |
---|
| 83 | moduleNames = map(filenameToModuleName, files) |
---|
| 84 | modules = map(__import__, moduleNames) |
---|
[2762] | 85 | |
---|
| 86 | # Fix up the system path |
---|
| 87 | for file in path_files: |
---|
| 88 | sys.path.remove(file) |
---|
| 89 | |
---|
[2638] | 90 | load = unittest.defaultTestLoader.loadTestsFromModule |
---|
| 91 | return unittest.TestSuite(map(load, modules)) |
---|
| 92 | |
---|
| 93 | if __name__ == '__main__': |
---|
| 94 | #unittest.main(defaultTest='regressionTest') |
---|
| 95 | |
---|
| 96 | suite = regressionTest() |
---|
| 97 | runner = unittest.TextTestRunner() #verbosity=2 |
---|
| 98 | runner.run(suite) |
---|