[svn r63822] simplifying and strictifying the internal calls to plugins using

the new "api" mechanism.

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-08 12:06:21 +02:00
parent d10eae0313
commit 0300b2109c
8 changed files with 31 additions and 25 deletions

View File

@ -438,8 +438,7 @@ class Directory(FSCollector):
return res
def consider_file(self, path):
return self.config.pytestplugins.call_each(
'pytest_collect_file', path=path, parent=self)
return self.config.api.pytest_collect_file(path=path, parent=self)
def consider_dir(self, path, usefilters=None):
if usefilters is not None:
@ -447,8 +446,8 @@ class Directory(FSCollector):
res = self.config.pytestplugins.call_firstresult(
'pytest_collect_recurse', path=path, parent=self)
if res is None or res:
return self.config.pytestplugins.call_each(
'pytest_collect_directory', path=path, parent=self)
return self.config.api.pytest_collect_directory(
path=path, parent=self)
class Item(Node):
""" a basic test item. """

View File

@ -35,6 +35,7 @@ class PluginHooks:
def pytest_pymodule_makeitem(self, modcol, name, obj):
""" return custom item/collector for a python object in a module, or None. """
pytest_pymodule_makeitem.firstresult = True
def pytest_itemrun(self, item, pdb=None):
""" run given test item and return test report. """
@ -52,14 +53,22 @@ class PluginHooks:
def pytest_item_makereport(self, item, excinfo, when, outerr):
""" return ItemTestReport event for the given test outcome. """
pytest_item_makereport.firstresult = True
# reporting hooks (invoked from pytest_terminal.py)
def pytest_report_teststatus(self, event):
def pytest_report_teststatus(self, rep):
""" return shortletter and verbose word. """
pytest_report_teststatus.firstresult = True
def pytest_terminal_summary(self, terminalreporter):
""" add additional section in terminal summary reporting. """
# doctest hooks (invoked from pytest_terminal.py)
def pytest_doctest_prepare_content(self, content):
""" return processed content for a given doctest"""
pytest_doctest_prepare_content.firstresult = True
class Events:
# Events
def pyevent(self, eventname, args, kwargs):

View File

@ -154,8 +154,7 @@ class ReSTSyntaxTest(py.test.collect.Item):
class DoctestText(py.test.collect.Item):
def runtest(self):
content = self._normalize_linesep()
newcontent = self.config.pytestplugins.call_firstresult(
'pytest_doctest_prepare_content', content=content)
newcontent = self.config.api.pytest_doctest_prepare_content(content=content)
if newcontent is not None:
content = newcontent
s = content

View File

@ -60,14 +60,14 @@ class TerminalReporter:
self.ensure_newline()
self._tw.sep(sep, title, **markup)
def getcategoryletterword(self, event):
res = self.config.pytestplugins.call_firstresult("pytest_report_teststatus", event=event)
def getcategoryletterword(self, rep):
res = self.config.api.pytest_report_teststatus(rep)
if res:
return res
for cat in 'skipped failed passed ???'.split():
if getattr(event, cat, None):
if getattr(rep, cat, None):
break
return cat, self.getoutcomeletter(event), self.getoutcomeword(event)
return cat, self.getoutcomeletter(rep), self.getoutcomeword(rep)
def getoutcomeletter(self, rep):
return rep.shortrepr
@ -224,7 +224,7 @@ class TerminalReporter:
if exitstatus in (0, 1, 2):
self.summary_failures()
self.summary_skips()
self.config.pytestplugins.call_each("pytest_terminal_summary", terminalreporter=self)
self.config.api.pytest_terminal_summary(terminalreporter=self)
if excrepr is not None:
self.summary_final_exc(excrepr)
if exitstatus == 2:

View File

@ -22,12 +22,12 @@ class XfailPlugin(object):
res.failed = True
return res
def pytest_report_teststatus(self, event):
def pytest_report_teststatus(self, rep):
""" return shortletter and verbose word. """
if 'xfail' in event.keywords:
if event.skipped:
if 'xfail' in rep.keywords:
if rep.skipped:
return "xfailed", "x", "xfail"
elif event.failed:
elif rep.failed:
return "xpassed", "P", "xpass"
# a hook implemented called by the terminalreporter instance/plugin

View File

@ -140,8 +140,8 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
return self.join(name)
def makeitem(self, name, obj):
res = self.config.pytestplugins.call_firstresult(
"pytest_pymodule_makeitem", modcol=self, name=name, obj=obj)
res = self.config.api.pytest_pymodule_makeitem(
modcol=self, name=name, obj=obj)
if res:
return res
if (self.classnamefilter(name)) and \
@ -349,8 +349,8 @@ class Function(FunctionMixin, py.test.collect.Item):
""" execute the given test function. """
if not self._deprecated_testexecution():
kw = self.lookup_allargs()
ret = self.config.pytestplugins.call_firstresult(
"pytest_pyfunc_call", pyfuncitem=self, args=self._args, kwargs=kw)
ret = self.config.api.pytest_pyfunc_call(
pyfuncitem=self, args=self._args, kwargs=kw)
def lookup_allargs(self):
kwargs = {}

View File

@ -102,12 +102,12 @@ class PytestPlugins(object):
assert not hasattr(self, '_config')
config.bus.register(self)
self._config = config
self.pyplugins.call_each("pytest_configure", config=self._config)
config.api.pytest_configure(config=self._config)
def do_unconfigure(self, config):
config = self._config
del self._config
self.pyplugins.call_each("pytest_unconfigure", config=config)
config.api.pytest_unconfigure(config=config)
config.bus.unregister(self)
def do_itemrun(self, item, pdb=None):

View File

@ -31,9 +31,8 @@ def basic_run_report(item, pdb=None):
raise
except:
excinfo = py.code.ExceptionInfo()
testrep = item.config.pytestplugins.call_firstresult(
"pytest_item_makereport", item=item,
excinfo=excinfo, when=when, outerr=outerr)
testrep = item.config.api.pytest_item_makereport(
item=item, excinfo=excinfo, when=when, outerr=outerr)
if pdb and testrep.failed:
tw = py.io.TerminalWriter()
testrep.toterminal(tw)