2009-05-21 05:12:37 +08:00
|
|
|
"""
|
2009-07-15 03:17:13 +08:00
|
|
|
write and report coverage data with 'figleaf'.
|
|
|
|
|
2009-05-21 05:12:37 +08:00
|
|
|
"""
|
2009-03-30 06:10:24 +08:00
|
|
|
import py
|
|
|
|
|
2009-07-09 01:57:45 +08:00
|
|
|
figleaf = py.test.importorskip("figleaf.annotate_html")
|
2009-03-30 06:10:24 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
group = parser.addgroup('figleaf options')
|
|
|
|
group.addoption('-F', action='store_true', default=False,
|
|
|
|
dest = 'figleaf',
|
2009-07-21 00:54:08 +08:00
|
|
|
help=('trace python coverage with figleaf and write HTML '
|
2009-05-19 05:26:16 +08:00
|
|
|
'for files below the current working dir'))
|
|
|
|
group.addoption('--figleaf-data', action='store', default='.figleaf',
|
|
|
|
dest='figleafdata',
|
2009-07-21 00:54:08 +08:00
|
|
|
help='path to coverage tracing file.')
|
2009-05-19 05:26:16 +08:00
|
|
|
group.addoption('--figleaf-html', action='store', default='html',
|
|
|
|
dest='figleafhtml',
|
|
|
|
help='path to the coverage html dir.')
|
2009-03-30 06:10:24 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_configure(config):
|
|
|
|
figleaf.start()
|
2009-03-30 06:10:24 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_terminal_summary(terminalreporter):
|
|
|
|
config = terminalreporter.config
|
|
|
|
datafile = py.path.local(config.getvalue('figleafdata'))
|
|
|
|
tw = terminalreporter._tw
|
|
|
|
tw.sep('-', 'figleaf')
|
|
|
|
tw.line('Writing figleaf data to %s' % (datafile))
|
|
|
|
figleaf.stop()
|
|
|
|
figleaf.write_coverage(str(datafile))
|
|
|
|
coverage = get_coverage(datafile, config)
|
|
|
|
reportdir = py.path.local(config.getvalue('figleafhtml'))
|
|
|
|
tw.line('Writing figleaf html to file://%s' % (reportdir))
|
|
|
|
figleaf.annotate_html.prepare_reportdir(str(reportdir))
|
|
|
|
exclude = []
|
|
|
|
figleaf.annotate_html.report_as_html(coverage,
|
|
|
|
str(reportdir), exclude, {})
|
2009-03-30 06:10:24 +08:00
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def get_coverage(datafile, config):
|
|
|
|
# basepath = config.topdir
|
|
|
|
basepath = py.path.local()
|
|
|
|
data = figleaf.read_coverage(str(datafile))
|
|
|
|
d = {}
|
|
|
|
coverage = figleaf.combine_coverage(d, data)
|
|
|
|
for path in coverage.keys():
|
|
|
|
if not py.path.local(path).relto(basepath):
|
|
|
|
del coverage[path]
|
|
|
|
return coverage
|
2009-03-30 07:12:41 +08:00
|
|
|
|
|
|
|
|
2009-03-30 06:40:44 +08:00
|
|
|
def test_functional(testdir):
|
2009-04-02 21:57:42 +08:00
|
|
|
py.test.importorskip("figleaf")
|
2009-05-19 05:26:16 +08:00
|
|
|
testdir.plugins.append("figleaf")
|
2009-03-30 06:40:44 +08:00
|
|
|
testdir.makepyfile("""
|
|
|
|
def f():
|
|
|
|
x = 42
|
|
|
|
def test_whatever():
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
result = testdir.runpytest('-F')
|
|
|
|
assert result.ret == 0
|
|
|
|
assert result.stdout.fnmatch_lines([
|
|
|
|
'*figleaf html*'
|
|
|
|
])
|
2009-04-01 01:58:02 +08:00
|
|
|
#print result.stdout.str()
|