source: anuga_core/source/anuga/interface/test_all.py @ 7731

Last change on this file since 7731 was 7728, checked in by James Hudson, 15 years ago

Added framework and tests for new model API.

File size: 2.7 KB
Line 
1#!/usr/bin/env python
2
3"""Regression testing framework
4This module will search for scripts in the same directory named
5test_*.py.  Each such script should be a test suite that tests a
6module through PyUnit. This script will aggregate all
7found test suites into one big test suite and run them all at once.
8"""
9
10# Author: Mark Pilgrim
11# Modified by Ole Nielsen
12
13import unittest
14import os
15
16
17#List files that should be excluded from the testing process.
18#E.g. if they are known to fail and under development
19#exclude = ['test_geo_reference.py','test_redfearn.py', 'test_point.py']
20
21
22def get_test_files(path):
23
24    import sys
25
26    files = os.listdir(path)
27
28    #Check sub directories
29    test_files = []
30    for file in files:
31        if os.path.isdir(file):
32            sys.path.append(file)
33            #print 'Recursing into', file
34            test_files += get_test_files(path + os.sep + file)
35        elif file[:5] == 'test_' and file[-2:] == 'py':
36            #print 'Appending', file
37            test_files.append(file)
38        else:
39            pass
40    return test_files
41
42
43
44def regressionTest():
45    import sys, os, re, unittest
46    path = os.path.split(sys.argv[0])[0] or os.getcwd()
47
48
49    files = get_test_files(path)
50
51
52
53    #test = re.compile('^test_[\w]*.py$', re.IGNORECASE)
54    #files = filter(test.search, files)
55
56
57    try:
58        files.remove(__file__)  #Remove self from list (Ver 2.3. or later)
59    except:
60        files.remove('test_all.py')
61
62    print 'Testing:'
63    for file in files:
64        print '  ' + file
65
66    if globals().has_key('exclude'):
67        for file in exclude:
68            files.remove(file)
69            print 'WARNING: File '+ file + ' excluded from testing'
70
71
72    filenameToModuleName = lambda f: os.path.splitext(f)[0]
73    #print "files",files
74    moduleNames = map(filenameToModuleName, files)
75    #print "moduleNames",moduleNames
76    modules = map(__import__, moduleNames)
77    load = unittest.defaultTestLoader.loadTestsFromModule
78    return unittest.TestSuite(map(load, modules))
79
80################################################################################
81
82if __name__ == '__main__':
83    from os import sep
84
85    #Attempt to compile all extensions
86    #execfile('..' + sep + 'utilities' + sep + 'compile.py')
87
88    #FIXME: Temporary measure
89    #os.chdir('..' + sep + 'utilities')
90    #execfile('compile.py')
91    #os.chdir('..' + sep + 'load_mesh')   
92   
93    #FIXME: Temporary measure
94    #os.chdir('..' + sep + 'triangle')
95    #execfile('compile.py')
96    #os.chdir('..' + sep + 'load_mesh')   
97   
98    #os.system('python compile.py')
99
100    #print regressionTest()
101    unittest.main(defaultTest='regressionTest')
Note: See TracBrowser for help on using the repository browser.