annotate autotest.py @ 507:b8e6de17eaa6

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