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:
parent
8b5fc60bd6
commit
9572c573d4
1 changed files with 28 additions and 1 deletions
|
@ -25,20 +25,47 @@
|
||||||
import doctest
|
import doctest
|
||||||
import unittest
|
import unittest
|
||||||
import gettext
|
import gettext
|
||||||
|
import sys
|
||||||
|
|
||||||
# Which package and which modules in the package should be tested?
|
# Which package and which modules in the package should be tested?
|
||||||
package = 'gpodder'
|
package = 'gpodder'
|
||||||
modules = ['util', 'libtagupdate']
|
modules = ['util', 'libtagupdate']
|
||||||
|
coverage_modules = []
|
||||||
|
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
||||||
for module in modules:
|
for module in modules:
|
||||||
m = __import__('.'.join((package, module)), fromlist=[module])
|
m = __import__('.'.join((package, module)), fromlist=[module])
|
||||||
|
coverage_modules.append(m)
|
||||||
# Emulate a globally-installed no-op gettext _() function
|
# Emulate a globally-installed no-op gettext _() function
|
||||||
if not hasattr(m, '_'):
|
if not hasattr(m, '_'):
|
||||||
setattr(m, '_', lambda x: x)
|
setattr(m, '_', lambda x: x)
|
||||||
suite.addTest(doctest.DocTestSuite(m))
|
suite.addTest(doctest.DocTestSuite(m))
|
||||||
|
|
||||||
runner = unittest.TextTestRunner(verbosity=2)
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue