Support Coverage reporting in gpodder.unittests

If "python-coverage" is installed, report the test
coverage for all currently-tested modules in gPodder
while doing the unittest with "make unittest".
This commit is contained in:
Thomas Perl 2009-03-24 15:42:39 +01:00
parent 8b5fc60bd6
commit 9572c573d4
1 changed files with 28 additions and 1 deletions

View File

@ -25,20 +25,47 @@
import doctest
import unittest
import gettext
import sys
# Which package and which modules in the package should be tested?
package = 'gpodder'
modules = ['util', 'libtagupdate']
coverage_modules = []
suite = unittest.TestSuite()
for module in modules:
m = __import__('.'.join((package, module)), fromlist=[module])
coverage_modules.append(m)
# Emulate a globally-installed no-op gettext _() function
if not hasattr(m, '_'):
setattr(m, '_', lambda x: x)
suite.addTest(doctest.DocTestSuite(m))
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
try:
import coverage
except ImportError:
coverage = None
if coverage is not None:
coverage.erase()
coverage.start()
result = runner.run(suite)
if not result.wasSuccessful():
sys.exit(1)
if coverage is not None:
coverage.stop()
coverage.report(coverage_modules)
coverage.erase()
if coverage is None:
print >>sys.stderr, """
No coverage reporting done (Python module "coverage" is missing)
Please install the python-coverage package to get coverage reporting.
"""