[2716] | 1 | """Regression testing framework |
---|
| 2 | This module will search for scripts in the same directory named |
---|
| 3 | test_*.py. Each such script should be a test suite that tests a |
---|
| 4 | module through PyUnit. This script will aggregate all |
---|
| 5 | found 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 | |
---|
| 11 | import unittest |
---|
| 12 | import 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 |
---|
| 17 | exclude_files = [] |
---|
| 18 | |
---|
| 19 | exclude_dirs = ['pypar_dist', #Special requirements |
---|
| 20 | 'props', 'wcprops', 'prop-base', 'text-base', '.svn', #Svn |
---|
| 21 | 'tmp'] |
---|
| 22 | |
---|
| 23 | def 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 | |
---|
| 53 | def 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 | |
---|
| 75 | if __name__ == '__main__': |
---|
| 76 | unittest.main(defaultTest='regressionTest') |
---|