[svn r63461] a few fixes, now figleaf writes files correctly.
also changed figleaf plugin to include only the files of the current working dir. --HG-- branch : trunk
This commit is contained in:
parent
cc0a984ffb
commit
371a6b9de9
|
@ -5,7 +5,6 @@ class DefaultPlugin:
|
||||||
|
|
||||||
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
|
||||||
pyfuncitem.obj(*args, **kwargs)
|
pyfuncitem.obj(*args, **kwargs)
|
||||||
return
|
|
||||||
|
|
||||||
def pytest_collect_file(self, path, parent):
|
def pytest_collect_file(self, path, parent):
|
||||||
ext = path.ext
|
ext = path.ext
|
||||||
|
|
|
@ -2,7 +2,8 @@ import py
|
||||||
|
|
||||||
class DoctestPlugin:
|
class DoctestPlugin:
|
||||||
def pytest_addoption(self, parser):
|
def pytest_addoption(self, parser):
|
||||||
parser.addoption("--doctest-modules",
|
group = parser.addgroup("doctest options")
|
||||||
|
group.addoption("--doctest-modules",
|
||||||
action="store_true", default=False,
|
action="store_true", default=False,
|
||||||
dest="doctestmodules")
|
dest="doctestmodules")
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ class FigleafPlugin:
|
||||||
group = parser.addgroup('figleaf options')
|
group = parser.addgroup('figleaf options')
|
||||||
group.addoption('-F', action='store_true', default=False,
|
group.addoption('-F', action='store_true', default=False,
|
||||||
dest = 'figleaf',
|
dest = 'figleaf',
|
||||||
help='trace coverage with figleaf and write HTML')
|
help=('trace coverage with figleaf and write HTML '
|
||||||
|
'for files below the current working dir'))
|
||||||
group.addoption('--figleaf-data', action='store', default='.figleaf',
|
group.addoption('--figleaf-data', action='store', default='.figleaf',
|
||||||
dest='figleafdata',
|
dest='figleafdata',
|
||||||
help='path coverage tracing file.')
|
help='path coverage tracing file.')
|
||||||
|
@ -25,32 +26,31 @@ class FigleafPlugin:
|
||||||
|
|
||||||
def pytest_terminal_summary(self, terminalreporter):
|
def pytest_terminal_summary(self, terminalreporter):
|
||||||
if hasattr(self, 'figleaf'):
|
if hasattr(self, 'figleaf'):
|
||||||
datafile = terminalreporter.config.getvalue('figleafdata')
|
config = terminalreporter.config
|
||||||
datafile = py.path.local(datafile)
|
datafile = py.path.local(config.getvalue('figleafdata'))
|
||||||
tw = terminalreporter._tw
|
tw = terminalreporter._tw
|
||||||
tw.sep('-', 'figleaf')
|
tw.sep('-', 'figleaf')
|
||||||
tw.line('Writing figleaf data to %s' % (datafile))
|
tw.line('Writing figleaf data to %s' % (datafile))
|
||||||
self.figleaf.stop()
|
self.figleaf.stop()
|
||||||
self.figleaf.write_coverage(str(datafile))
|
self.figleaf.write_coverage(str(datafile))
|
||||||
coverage = self.get_coverage(datafile,
|
coverage = self.get_coverage(datafile, config)
|
||||||
terminalreporter.config.topdir)
|
|
||||||
|
|
||||||
reportdir = terminalreporter.config.getvalue('figleafhtml')
|
reportdir = py.path.local(config.getvalue('figleafhtml'))
|
||||||
reportdir = py.path.local(reportdir)
|
|
||||||
tw.line('Writing figleaf html to file://%s' % (reportdir))
|
tw.line('Writing figleaf html to file://%s' % (reportdir))
|
||||||
self.figleaf.annotate_html.prepare_reportdir(str(reportdir))
|
self.figleaf.annotate_html.prepare_reportdir(str(reportdir))
|
||||||
exclude = []
|
exclude = []
|
||||||
self.figleaf.annotate_html.report_as_html(coverage,
|
self.figleaf.annotate_html.report_as_html(coverage,
|
||||||
str(reportdir), exclude, {})
|
str(reportdir), exclude, {})
|
||||||
|
|
||||||
def get_coverage(self, datafile, topdir):
|
def get_coverage(self, datafile, config):
|
||||||
|
# basepath = config.topdir
|
||||||
|
basepath = py.path.local()
|
||||||
data = self.figleaf.read_coverage(str(datafile))
|
data = self.figleaf.read_coverage(str(datafile))
|
||||||
d = {}
|
d = {}
|
||||||
coverage = self.figleaf.combine_coverage(d, data)
|
coverage = self.figleaf.combine_coverage(d, data)
|
||||||
for path in coverage.keys():
|
for path in coverage.keys():
|
||||||
if not py.path.local(path).relto(topdir):
|
if not py.path.local(path).relto(basepath):
|
||||||
del coverage[path]
|
del coverage[path]
|
||||||
|
|
||||||
return coverage
|
return coverage
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,4 +71,4 @@ def test_functional(testdir):
|
||||||
assert result.stdout.fnmatch_lines([
|
assert result.stdout.fnmatch_lines([
|
||||||
'*figleaf html*'
|
'*figleaf html*'
|
||||||
])
|
])
|
||||||
print result.stdout.str()
|
#print result.stdout.str()
|
||||||
|
|
|
@ -29,6 +29,7 @@ class PluginTester(Support):
|
||||||
# FSTester = self.pyfuncitem.config.pytestplugins.getpluginattr("pytester", "FSTester")
|
# FSTester = self.pyfuncitem.config.pytestplugins.getpluginattr("pytester", "FSTester")
|
||||||
from pytest_pytester import TmpTestdir
|
from pytest_pytester import TmpTestdir
|
||||||
crunner = TmpTestdir(self.pyfuncitem)
|
crunner = TmpTestdir(self.pyfuncitem)
|
||||||
|
self.pyfuncitem.addfinalizer(crunner.finalize)
|
||||||
#
|
#
|
||||||
for colitem in self.pyfuncitem.listchain():
|
for colitem in self.pyfuncitem.listchain():
|
||||||
if isinstance(colitem, py.test.collect.Module) and \
|
if isinstance(colitem, py.test.collect.Module) and \
|
||||||
|
|
|
@ -15,7 +15,6 @@ class PytesterPlugin:
|
||||||
|
|
||||||
def pytest_funcarg__testdir(self, pyfuncitem):
|
def pytest_funcarg__testdir(self, pyfuncitem):
|
||||||
tmptestdir = TmpTestdir(pyfuncitem)
|
tmptestdir = TmpTestdir(pyfuncitem)
|
||||||
pyfuncitem.addfinalizer(tmptestdir.finalize)
|
|
||||||
return tmptestdir
|
return tmptestdir
|
||||||
|
|
||||||
def pytest_funcarg__EventRecorder(self, pyfuncitem):
|
def pytest_funcarg__EventRecorder(self, pyfuncitem):
|
||||||
|
@ -56,6 +55,11 @@ class TmpTestdir:
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
self._syspathremove = []
|
self._syspathremove = []
|
||||||
self.chdir() # always chdir
|
self.chdir() # always chdir
|
||||||
|
assert hasattr(self, '_olddir')
|
||||||
|
self.pyfuncitem.addfinalizer(self.finalize)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<TmpTestdir %r>" % (self.tmpdir,)
|
||||||
|
|
||||||
def Config(self, pyplugins=None, topdir=None):
|
def Config(self, pyplugins=None, topdir=None):
|
||||||
if topdir is None:
|
if topdir is None:
|
||||||
|
@ -69,7 +73,7 @@ class TmpTestdir:
|
||||||
self._olddir.chdir()
|
self._olddir.chdir()
|
||||||
|
|
||||||
def chdir(self):
|
def chdir(self):
|
||||||
old = self.testdir.chdir()
|
old = self.tmpdir.chdir()
|
||||||
if not hasattr(self, '_olddir'):
|
if not hasattr(self, '_olddir'):
|
||||||
self._olddir = old
|
self._olddir = old
|
||||||
|
|
||||||
|
@ -110,9 +114,6 @@ class TmpTestdir:
|
||||||
def mkdir(self, name):
|
def mkdir(self, name):
|
||||||
return self.tmpdir.mkdir(name)
|
return self.tmpdir.mkdir(name)
|
||||||
|
|
||||||
def chdir(self):
|
|
||||||
return self.tmpdir.chdir()
|
|
||||||
|
|
||||||
def genitems(self, colitems):
|
def genitems(self, colitems):
|
||||||
return list(self.session.genitems(colitems))
|
return list(self.session.genitems(colitems))
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ class TerminalReporter:
|
||||||
self.gateway2info = {}
|
self.gateway2info = {}
|
||||||
|
|
||||||
def write_fspath_result(self, fspath, res):
|
def write_fspath_result(self, fspath, res):
|
||||||
|
fspath = self.curdir.bestrelpath(fspath)
|
||||||
if fspath != self.currentfspath:
|
if fspath != self.currentfspath:
|
||||||
self._tw.line()
|
self._tw.line()
|
||||||
relpath = self.curdir.bestrelpath(fspath)
|
relpath = self.curdir.bestrelpath(fspath)
|
||||||
|
@ -138,6 +139,8 @@ class TerminalReporter:
|
||||||
def pyevent_itemstart(self, item, node=None):
|
def pyevent_itemstart(self, item, node=None):
|
||||||
if self.config.option.debug:
|
if self.config.option.debug:
|
||||||
info = item.repr_metainfo()
|
info = item.repr_metainfo()
|
||||||
|
node
|
||||||
|
n
|
||||||
line = info.verboseline(basedir=self.curdir) + " "
|
line = info.verboseline(basedir=self.curdir) + " "
|
||||||
extra = ""
|
extra = ""
|
||||||
if node:
|
if node:
|
||||||
|
|
Loading…
Reference in New Issue