annotate test.py @ 193:92ee9896020d

Add option to test a module given on the command line.
author Arnaud Bergeron <abergeron@gmail.com>
date Tue, 02 Mar 2010 17:00:59 -0500
parents ff26436d42d6
children 6ea5dcf0541e
rev   line source
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
1 import doctest, sys, pkgutil
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
2
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
3 def runTests():
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
4 import ift6266
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
5 for (_, name, ispkg) in pkgutil.walk_packages(ift6266.__path__, ift6266.__name__+'.'):
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
6 if not ispkg:
174
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 162
diff changeset
7 if name.startswith('ift6266.scripts.') or \
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 162
diff changeset
8 name.startswith('ift6266.data_generation.transformations.pycaptcha.') or \
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 162
diff changeset
9 name in ['ift6266.test',
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 162
diff changeset
10 'ift6266.data_generation.transformations.testmod',
ff26436d42d6 Make data_generation.transformations importable and fixup test.py to not try some of the modules.
Arnaud Bergeron <abergeron@gmail.com>
parents: 162
diff changeset
11 'ift6266.data_generation.transformations.gimp_script']:
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
12 continue
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
13 test(name)
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
14
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
15 def test(name, options = doctest.ELLIPSIS or doctest.DONT_ACCEPT_TRUE_FOR_1):
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
16 import ift6266
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
17 predefs = ift6266.__dict__
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
18 print "Testing:", name
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
19 __import__(name)
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
20 doctest.testmod(sys.modules[name], extraglobs=predefs, optionflags=options)
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
21
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
22 if __name__ == '__main__':
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
23 if len(sys.argv) > 1:
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
24 for mod in sys.argv[1:]:
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
25 test(mod)
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
26 else:
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
27 runTests()