comparison autotest.py @ 285:23981827b794

add autotest.py. It run all unittest
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Fri, 06 Jun 2008 13:53:02 -0400
parents
children
comparison
equal deleted inserted replaced
284:8e923cb2e8fc 285:23981827b794
1 import unittest, os, sys, traceback
2
3 def test_root_dir(debugmode=False):
4 suite = None
5 filenames = os.listdir('.')
6 for filename in filenames:
7 if filename[-3:] == '.py' and filename.startswith('_test'):
8 #print >>sys.stderr, 'Loading', modname
9 modname = filename[0:-3]
10
11 try:
12 module = __import__(modname)
13 except Exception, e:
14 print >>sys.stderr, "===================================================="
15 print >>sys.stderr, "Failed to load %s.py" % modname
16 print >>sys.stderr, "===================================================="
17 traceback.print_exc()
18 print >>sys.stderr, "===================================================="
19 continue
20
21 tests = unittest.TestLoader().loadTestsFromModule(module)
22 if tests.countTestCases() > 0:
23 print >>sys.stderr, 'Testing', modname
24 if suite is None:
25 suite = tests
26 else:
27 suite.addTests(tests)
28 if suite is None:
29 print >>sys.stderr, "No suite found"
30 sys.exit(1)
31 if debugmode:
32 suite.debug()
33 else:
34 unittest.TextTestRunner(verbosity=1).run(suite)
35
36 if __name__ == '__main__':
37
38 def printUsage():
39 print >>sys.stderr, "Bad argument: ",sys.argv
40 print >>sys.stderr, "only --debug is supported"
41 sys.exit(1)
42 debugparam=""
43
44 if len(sys.argv)==2:
45 if sys.argv[1]=="--debug":
46 debugparam="--debug"
47 sys.argv.remove(debugparam)
48 else:
49 printUsage()
50 elif len(sys.argv)>2:
51 printUsage()
52
53 test_root_dir(debugparam!="")
54