3 Test runner for main pygr tests.
5 Collects all files ending in _test.py and executes them.
8 import os
, sys
, re
, unittest
, shutil
, re
, shutil
9 from testlib
import testutil
, testoptions
10 from testlib
.unittest_extensions
import PygrTestRunner
11 from pygr
import logger
13 disable_threshold
= 0 # global logging override
16 "Returns all file names that end in _test.py"
17 patt
= re
.compile("_test.py$")
18 mods
= os
.listdir(os
.path
.normpath(os
.path
.dirname(__file__
)))
19 mods
= filter(patt
.search
, mods
)
21 # some predictable order...
25 def run(targets
, options
):
26 "Imports and runs the modules names that are contained in the 'targets'"
28 success
= errors
= skipped
= 0
30 # run the tests by importing the module and getting its test suite
33 testutil
.info('running tests for module %s' % name
)
34 l
= unittest
.TestLoader()
35 suite
= l
.loadTestsFromName(name
)
37 runner
= PygrTestRunner(verbosity
=options
.verbosity
,
40 logger
.disable(disable_threshold
) # set global override
41 results
= runner
.run(suite
)
42 logger
.disable(0) # clear global override
44 # count tests and errors
45 success
+= results
.testsRun
- \
46 len(results
.errors
) - \
47 len(results
.failures
) - \
50 errors
+= len(results
.errors
) + len(results
.failures
)
51 skipped
+= len(results
.skipped
)
53 # if we're in strict mode stop on errors
54 if options
.strict
and errors
:
55 testutil
.error( "strict mode stops on errors" )
59 testutil
.error( "unable to import module '%s'" % name
)
62 testutil
.info('=' * 59)
64 %s tests passed, %s tests failed, %s tests skipped; %d total''' % \
65 (success
, errors
, skipped
, success
+ errors
+ skipped
))
67 return (success
, errors
, skipped
)
69 if __name__
== '__main__':
70 # Make sure no messages are filtered out at first
73 # gets the prebuild option parser
74 parser
= testoptions
.option_parser()
77 options
, args
= parser
.parse_args()
79 # modules: from command line args or all modules
80 targets
= args
or all_tests()
82 # get rid of the .py ending in case full module names were passed in
86 if t
.endswith('.py'): t
= t
[:-3]
87 stripped_targets
.append(t
)
88 targets
= stripped_targets
91 testutil
.default_xmlrpc_port
= options
.port
95 targets
= [ name
for name
in all_tests() if name
not in targets
]
97 # disables debug messages at < 2 verbosity, debug+info at < 1
98 if options
.verbosity
< 1:
99 disable_threshold
= 'INFO' # Should implicity disable DEBUG as well
100 elif options
.verbosity
< 2:
101 disable_threshold
= 'DEBUG'
103 # cleans full entire test directory
105 testutil
.TEMPROOT
.reset()
106 testutil
.TEMPDIR
= testutil
.TEMPROOT
.path
# yikes!
108 # list patterns matching files to be removed here
110 "*.seqlen", "*.pureseq", "*.nin", "*.pin", "*.psd",
111 "*.psi", "*.psq", "*.psd", "*.nni", "*.nhr",
112 "*.nsi", "*.nsd", "*.nsq", "*.nnd",
114 testutil
.remove_files(path
=testutil
.DATADIR
, patterns
=patterns
)
118 good
, bad
, skip
= testutil
.generate_coverage(run
, 'coverage',
122 good
, bad
, skip
= run(targets
=targets
, options
=options
)