-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_doctests.py
57 lines (47 loc) · 1.59 KB
/
run_doctests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
import doctest, sys, glob, os, os.path
packages = [ 'neco',
'neco.core',
'neco.backends',
'neco.backends.python',
'neco.backends.cython',
'neco.opt' ]
def search_modules(package_str):
""" Search all modules of a package.
@param package_str: dotted package name, ex. foo.bar
@type package_str: C{str}
"""
l = package_str.split('.')
l.append('*.py')
path = apply(os.path.join, l)
python_file_paths = glob.glob(path)
return [ mod.replace('.py', '').replace('/__init__', '').replace(os.sep, '.')
for mod in python_file_paths ]
tests = 0
failed = 0
def test (module) :
global tests, failed
tests += 1
print "Testing '%s'" % module.__name__
ret_code, t = doctest.testmod(module, # verbose=True,
optionflags=doctest.NORMALIZE_WHITESPACE
| doctest.REPORT_ONLY_FIRST_FAILURE
| doctest.ELLIPSIS)
if ret_code != 0:
failed += 1
def run_tests():
for package in packages:
modules = search_modules(package)
for module in modules:
try :
__import__(module)
test(sys.modules[module])
except :
print " Could not test %r:" % module
c, e, t = sys.exc_info()
print " %s: %s" % (c.__name__, e)
print
print "{tests} files tested, {failed} failed.".format(tests=(tests - failed), failed=failed)
print
if __name__ == '__main__':
run_tests()