comparison 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
comparison
equal deleted inserted replaced
189:0d0677773533 193:92ee9896020d
1 import doctest, sys, pkgutil 1 import doctest, sys, pkgutil
2 2
3 def runTests(options = doctest.ELLIPSIS or doctest.DONT_ACCEPT_TRUE_FOR_1): 3 def runTests():
4 import ift6266 4 import ift6266
5 predefs = ift6266.__dict__
6 for (_, name, ispkg) in pkgutil.walk_packages(ift6266.__path__, ift6266.__name__+'.'): 5 for (_, name, ispkg) in pkgutil.walk_packages(ift6266.__path__, ift6266.__name__+'.'):
7 if not ispkg: 6 if not ispkg:
8 if name.startswith('ift6266.scripts.') or \ 7 if name.startswith('ift6266.scripts.') or \
9 name.startswith('ift6266.data_generation.transformations.pycaptcha.') or \ 8 name.startswith('ift6266.data_generation.transformations.pycaptcha.') or \
10 name in ['ift6266.test', 9 name in ['ift6266.test',
11 'ift6266.data_generation.transformations.testmod', 10 'ift6266.data_generation.transformations.testmod',
12 'ift6266.data_generation.transformations.gimp_script']: 11 'ift6266.data_generation.transformations.gimp_script']:
13 continue 12 continue
14 print "Testing:", name 13 test(name)
15 __import__(name)
16 doctest.testmod(sys.modules[name], extraglobs=predefs, optionflags=options)
17 14
15 def test(name, options = doctest.ELLIPSIS or doctest.DONT_ACCEPT_TRUE_FOR_1):
16 import ift6266
17 predefs = ift6266.__dict__
18 print "Testing:", name
19 __import__(name)
20 doctest.testmod(sys.modules[name], extraglobs=predefs, optionflags=options)
21
18 if __name__ == '__main__': 22 if __name__ == '__main__':
19 runTests() 23 if len(sys.argv) > 1:
24 for mod in sys.argv[1:]:
25 test(mod)
26 else:
27 runTests()