source: inundation/test_all.py @ 2744

Last change on this file since 2744 was 2744, checked in by duncan, 18 years ago

test_parallel_sw.py removed since its breaking test_all.py. pmesh put back in.

File size: 2.7 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', 'test_parallel_sw.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
28print "The following directories will be skipped over;"
29for dir in exclude_dirs:
30    print dir
31print ""
32
33def get_test_files(path):
34
35    import sys
36
37    try:
38        files = os.listdir(path)
39    except:
40        return []
41
42    #Check sub directories
43    test_files = []
44
45    for file in files:
46
47        #Exclude svn admin dirs
48        if file in exclude_dirs:
49            continue
50
51        absolute_filename = path + os.sep + file
52
53        if os.path.isdir(absolute_filename):
54            sys.path.append(file) #FIXME: May cause name conflicts between pyvolution\mesh.py and pmesh\mesh.py on some systems
55            print 'Recursing into', file
56            test_files += get_test_files(absolute_filename)
57        elif file.startswith('test_') and file.endswith('.py'):
58            test_files.append(file)
59        else:
60            pass
61    return test_files
62
63
64
65def regressionTest():
66    import os, unittest
67    path = os.getcwd()
68
69    files = [x for x in  get_test_files(path) if not x == 'test_all.py']
70
71    print 'Testing path %s:' %('...'+path[-50:])
72    for file in files:
73        print '  ' + file
74
75    if globals().has_key('exclude_files'):
76        for file in exclude_files:
77            files.remove(file)
78            print 'WARNING: File '+ file + ' excluded from testing'
79
80
81    filenameToModuleName = lambda f: os.path.splitext(f)[0]
82    moduleNames = map(filenameToModuleName, files)
83    modules = map(__import__, moduleNames)
84    load = unittest.defaultTestLoader.loadTestsFromModule
85    return unittest.TestSuite(map(load, modules))
86
87if __name__ == '__main__':
88    #unittest.main(defaultTest='regressionTest')
89
90    suite = regressionTest()
91    runner = unittest.TextTestRunner() #verbosity=2
92    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.