source: inundation/test_all.py @ 2378

Last change on this file since 2378 was 2367, checked in by ole, 19 years ago

Comment

File size: 2.4 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
17exclude_files = ['test_metis.py', 'test_version.py',
18                 'test_interpolate.py',# this is under development
19                 ]
20                 #'test_calculate_region.py', 'test_calculate_point.py']
21                 #'test_init.py']
22
23exclude_dirs = ['pypar_dist', #Special requirements
24                'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn
25                'tmp']               
26
27
28def get_test_files(path):
29
30    import sys
31
32    try:
33        files = os.listdir(path)
34    except:
35        return []
36
37    #Check sub directories
38    test_files = []
39    for file in files:
40
41        #Exclude svn admin dirs
42        if file in exclude_dirs: continue
43       
44        absolute_filename = path + os.sep + file
45
46        if os.path.isdir(absolute_filename):
47            sys.path.append(file)            #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems
48            print 'Recursing into', file
49            test_files += get_test_files(absolute_filename)
50        elif file.startswith('test_') and file.endswith('.py'):
51            test_files.append(file)
52        else:
53            pass
54    return test_files
55
56
57
58def regressionTest():
59    import os, unittest
60    path = os.getcwd()
61   
62    files = [x for x in  get_test_files(path) if not x == 'test_all.py']
63   
64    print 'Testing path %s:' %('...'+path[-50:])
65    for file in files:
66        print '  ' + file
67
68    if globals().has_key('exclude_files'):
69        for file in exclude_files:
70            files.remove(file)
71            print 'WARNING: File '+ file + ' excluded from testing'
72
73
74    filenameToModuleName = lambda f: os.path.splitext(f)[0]
75    moduleNames = map(filenameToModuleName, files)
76    modules = map(__import__, moduleNames)
77    load = unittest.defaultTestLoader.loadTestsFromModule
78    return unittest.TestSuite(map(load, modules))
79
80if __name__ == '__main__':
81    unittest.main(defaultTest='regressionTest')
Note: See TracBrowser for help on using the repository browser.