[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:
hpk 2009-03-31 19:58:02 +02:00
parent cc0a984ffb
commit 371a6b9de9
6 changed files with 23 additions and 18 deletions

View File

@ -5,7 +5,6 @@ class DefaultPlugin:
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
pyfuncitem.obj(*args, **kwargs)
return
def pytest_collect_file(self, path, parent):
ext = path.ext

View File

@ -2,7 +2,8 @@ import py
class DoctestPlugin:
def pytest_addoption(self, parser):
parser.addoption("--doctest-modules",
group = parser.addgroup("doctest options")
group.addoption("--doctest-modules",
action="store_true", default=False,
dest="doctestmodules")

View File

@ -5,7 +5,8 @@ class FigleafPlugin:
group = parser.addgroup('figleaf options')
group.addoption('-F', action='store_true', default=False,
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',
dest='figleafdata',
help='path coverage tracing file.')
@ -25,32 +26,31 @@ class FigleafPlugin:
def pytest_terminal_summary(self, terminalreporter):
if hasattr(self, 'figleaf'):
datafile = terminalreporter.config.getvalue('figleafdata')
datafile = py.path.local(datafile)
config = terminalreporter.config
datafile = py.path.local(config.getvalue('figleafdata'))
tw = terminalreporter._tw
tw.sep('-', 'figleaf')
tw.line('Writing figleaf data to %s' % (datafile))
self.figleaf.stop()
self.figleaf.write_coverage(str(datafile))
coverage = self.get_coverage(datafile,
terminalreporter.config.topdir)
coverage = self.get_coverage(datafile, config)
reportdir = terminalreporter.config.getvalue('figleafhtml')
reportdir = py.path.local(reportdir)
reportdir = py.path.local(config.getvalue('figleafhtml'))
tw.line('Writing figleaf html to file://%s' % (reportdir))
self.figleaf.annotate_html.prepare_reportdir(str(reportdir))
exclude = []
self.figleaf.annotate_html.report_as_html(coverage,
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))
d = {}
coverage = self.figleaf.combine_coverage(d, data)
for path in coverage.keys():
if not py.path.local(path).relto(topdir):
if not py.path.local(path).relto(basepath):
del coverage[path]
return coverage
@ -71,4 +71,4 @@ def test_functional(testdir):
assert result.stdout.fnmatch_lines([
'*figleaf html*'
])
print result.stdout.str()
#print result.stdout.str()

View File

@ -29,6 +29,7 @@ class PluginTester(Support):
# FSTester = self.pyfuncitem.config.pytestplugins.getpluginattr("pytester", "FSTester")
from pytest_pytester import TmpTestdir
crunner = TmpTestdir(self.pyfuncitem)
self.pyfuncitem.addfinalizer(crunner.finalize)
#
for colitem in self.pyfuncitem.listchain():
if isinstance(colitem, py.test.collect.Module) and \

View File

@ -15,7 +15,6 @@ class PytesterPlugin:
def pytest_funcarg__testdir(self, pyfuncitem):
tmptestdir = TmpTestdir(pyfuncitem)
pyfuncitem.addfinalizer(tmptestdir.finalize)
return tmptestdir
def pytest_funcarg__EventRecorder(self, pyfuncitem):
@ -56,6 +55,11 @@ class TmpTestdir:
self.plugins = []
self._syspathremove = []
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):
if topdir is None:
@ -69,7 +73,7 @@ class TmpTestdir:
self._olddir.chdir()
def chdir(self):
old = self.testdir.chdir()
old = self.tmpdir.chdir()
if not hasattr(self, '_olddir'):
self._olddir = old
@ -110,9 +114,6 @@ class TmpTestdir:
def mkdir(self, name):
return self.tmpdir.mkdir(name)
def chdir(self):
return self.tmpdir.chdir()
def genitems(self, colitems):
return list(self.session.genitems(colitems))

View File

@ -29,6 +29,7 @@ class TerminalReporter:
self.gateway2info = {}
def write_fspath_result(self, fspath, res):
fspath = self.curdir.bestrelpath(fspath)
if fspath != self.currentfspath:
self._tw.line()
relpath = self.curdir.bestrelpath(fspath)
@ -138,6 +139,8 @@ class TerminalReporter:
def pyevent_itemstart(self, item, node=None):
if self.config.option.debug:
info = item.repr_metainfo()
node
n
line = info.verboseline(basedir=self.curdir) + " "
extra = ""
if node: