diff options
author | gbrandl <devnull@localhost> | 2007-02-18 09:55:07 +0100 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2007-02-18 09:55:07 +0100 |
commit | fd77019bad3bc2f829a83b25e75cf61ddcc544a1 (patch) | |
tree | 7d453f96ecf63ae1d4c59ac754106772bc68e76c /tests/run.py | |
parent | 281b60d088c493f8eb8e0ec32fe637e2622854f4 (diff) | |
download | pygments-fd77019bad3bc2f829a83b25e75cf61ddcc544a1.tar.gz |
[svn] Add support for code coverage analysis.
Diffstat (limited to 'tests/run.py')
-rw-r--r-- | tests/run.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/run.py b/tests/run.py index 66048391..debaaf7a 100644 --- a/tests/run.py +++ b/tests/run.py @@ -18,6 +18,11 @@ import __builtin__ from os.path import dirname, basename, join, abspath +try: + import coverage +except ImportError: + coverage = None + testdir = abspath(dirname(__file__)) # useful for all tests @@ -57,11 +62,11 @@ class QuietTestRunner(object): return result -def run_tests(): +def run_tests(with_coverage=False): # needed to avoid confusion involving atexit handlers import logging - orig_modules = sys.modules.keys() + #orig_modules = sys.modules.keys() if sys.argv[1:]: # test only files given on cmdline @@ -73,10 +78,15 @@ def run_tests(): WIDTH = 70 - print >>sys.stderr, 'Pygments Test Suite running, stand by...'.center(WIDTH) + print >>sys.stderr, ('Pygments Test Suite running %s, stand by...' % + (with_coverage and "with coverage analysis" or "")).center(WIDTH) print >>sys.stderr, ('(using Python %s)' % sys.version.split()[0]).center(WIDTH) print >>sys.stderr, '='*WIDTH + if with_coverage: + coverage.erase() + coverage.start() + for testfile in files: globs = {} try: @@ -107,14 +117,26 @@ def run_tests(): print >>sys.stderr, '%d of %d tests failed.' % \ (error_test_count, total_test_count) print >>sys.stderr, 'Tests failed in:', ', '.join(failed) - return 1 + ret = 1 else: if total_test_count == 1: print >>sys.stderr, '1 test happy.' else: print >>sys.stderr, 'All %d tests happy.' % total_test_count - return 0 + ret = 0 + + if with_coverage: + coverage.stop() + modules = [mod for name, mod in sys.modules.iteritems() + if name.startswith('pygments.') and mod] + coverage.report(modules) + + return ret if __name__ == '__main__': - sys.exit(run_tests()) + with_coverage = False + if sys.argv[1:2] == ['-C']: + with_coverage = bool(coverage) + del sys.argv[1] + sys.exit(run_tests(with_coverage)) |