annotate test.py @ 301:be45e7db7cd4

Fix last-minute bugs in the code.
author Arnaud Bergeron <abergeron@gmail.com>
date Mon, 29 Mar 2010 18:14:30 -0400
parents 6ea5dcf0541e
children
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
195
92c9a6c48ce9 Add option for test.py to test modules specified on the command-line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
15 def test(name):
193
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__
195
92c9a6c48ce9 Add option for test.py to test modules specified on the command-line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
18 options = doctest.ELLIPSIS or doctest.DONT_ACCEPT_TRUE_FOR_1
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
19 print "Testing:", name
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
20 __import__(name)
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
21 doctest.testmod(sys.modules[name], extraglobs=predefs, optionflags=options)
160
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
22
68160fd149fe Simple script to doctest all modules beneath ift6266.
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
23 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
24 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
25 for mod in sys.argv[1:]:
195
92c9a6c48ce9 Add option for test.py to test modules specified on the command-line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
26 if mod.endswith('.py'):
92c9a6c48ce9 Add option for test.py to test modules specified on the command-line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
27 mod = mod[:-3]
193
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
28 test(mod)
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
29 else:
92ee9896020d Add option to test a module given on the command line.
Arnaud Bergeron <abergeron@gmail.com>
parents: 174
diff changeset
30 runTests()