source: anuga_core/source/anuga/advection/test_all.py @ 7737

Last change on this file since 7737 was 7317, checked in by rwilson, 15 years ago

Replaced 'print' statements with log.critical() calls.

File size: 2.6 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 = [] 
18
19
20def get_test_files(path):
21
22    import sys
23
24    files = os.listdir(path)
25
26    #Check sub directories
27    test_files = []
28    for file in files:
29        if os.path.isdir(file):
30            sys.path.append(file)
31            test_files += get_test_files(path + os.sep + file)
32        elif file[:5] == 'test_' and file[-2:] == 'py':
33            test_files.append(file)
34        else:
35            pass
36    return test_files
37
38
39
40def regressionTest():
41    import sys, os, re, unittest
42    path = os.path.split(sys.argv[0])[0] or os.getcwd()
43
44
45    files = get_test_files(path)
46
47
48
49    #test = re.compile('^test_[\w]*.py$', re.IGNORECASE)
50    #files = filter(test.search, files)
51
52
53    try:
54        files.remove(__file__)  #Remove self from list (Ver 2.3. or later)
55    except:
56        files.remove('test_all.py')
57
58    print 'Testing:'
59    for file in files:
60        print '  ' + file
61
62    if globals().has_key('exclude'):
63        for file in exclude:
64            files.remove(file)
65            print 'WARNING: File '+ file + ' excluded from testing'
66
67
68    filenameToModuleName = lambda f: os.path.splitext(f)[0]
69    #print "files",files
70    moduleNames = map(filenameToModuleName, files)
71    #print "moduleNames",moduleNames
72    modules = map(__import__, moduleNames)
73    load = unittest.defaultTestLoader.loadTestsFromModule
74    return unittest.TestSuite(map(load, modules))
75
76if __name__ == '__main__':
77
78    from os import sep
79
80    #Attempt to compile all extensions
81    #execfile('..' + sep + 'utilities' + sep + 'compile.py')
82
83    #FIXME: Temporary measure
84    #os.chdir('..' + sep + 'utilities')
85    #execfile('compile.py')
86    #os.chdir('..' + sep + 'pyvolution')   
87   
88    #FIXME: Temporary measure
89    #os.chdir('..' + sep + 'triangle')
90    #execfile('compile.py')
91    #os.chdir('..' + sep + 'pyvolution')   
92   
93    #os.system('python compile.py')
94
95    #print regressionTest()
96    #unittest.main(defaultTest='regressionTest')
97   
98    suite = regressionTest()
99    runner = unittest.TextTestRunner() #(verbosity=2)
100    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.