source: development/pyvolution-1d/test_all.py @ 2716

Last change on this file since 2716 was 2716, checked in by jakeman, 18 years ago

Adding new files

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