[svn r63889] renaming/streamlining missing event usage

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-09 02:45:46 +02:00
parent cd038ee708
commit cd322bd528
7 changed files with 10 additions and 40 deletions

View File

@ -3,7 +3,7 @@ pytest_plugins = "pytester"
from py.__.execnet.gateway import ExecnetAPI from py.__.execnet.gateway import ExecnetAPI
class TestExecnetEvents: class TestExecnetEvents:
def test_popengateway_events(self, _pytest): def test_popengateway(self, _pytest):
rec = _pytest.getcallrecorder(ExecnetAPI) rec = _pytest.getcallrecorder(ExecnetAPI)
gw = py.execnet.PopenGateway() gw = py.execnet.PopenGateway()
call = rec.popcall("pyexecnet_gateway_init") call = rec.popcall("pyexecnet_gateway_init")

View File

@ -254,7 +254,7 @@ class TestDSession:
assert loopstate.testsfailed assert loopstate.testsfailed
assert loopstate.shuttingdown assert loopstate.shuttingdown
def test_shuttingdown_filters_events(self, testdir): def test_shuttingdown_filters(self, testdir):
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
session = DSession(item.config) session = DSession(item.config)
node = MockNode() node = MockNode()

View File

@ -1,5 +1,5 @@
""" """
API definitions for pytest plugin hooks and events API definitions for pytest plugin hooks
""" """
class PluginHooks: class PluginHooks:
@ -68,6 +68,7 @@ class PluginHooks:
""" return processed content for a given doctest""" """ return processed content for a given doctest"""
pytest_doctest_prepare_content.firstresult = True pytest_doctest_prepare_content.firstresult = True
def pytest_itemstart(self, item, node=None): def pytest_itemstart(self, item, node=None):
""" test item gets collected. """ """ test item gets collected. """

View File

@ -87,8 +87,7 @@ class TestDoctests:
""") """)
for x in (testdir.tmpdir, checkfile): for x in (testdir.tmpdir, checkfile):
#print "checking that %s returns custom items" % (x,) #print "checking that %s returns custom items" % (x,)
items, events = testdir.inline_genitems(x) items, sorter = testdir.inline_genitems(x)
print events.events
assert len(items) == 1 assert len(items) == 1
assert isinstance(items[0], DoctestTextfile) assert isinstance(items[0], DoctestTextfile)
@ -97,7 +96,6 @@ class TestDoctests:
path = testdir.makepyfile(whatever="#") path = testdir.makepyfile(whatever="#")
for p in (path, testdir.tmpdir): for p in (path, testdir.tmpdir):
items, evrec = testdir.inline_genitems(p, '--doctest-modules') items, evrec = testdir.inline_genitems(p, '--doctest-modules')
print evrec.events
assert len(items) == 1 assert len(items) == 1
assert isinstance(items[0], DoctestModule) assert isinstance(items[0], DoctestModule)

View File

@ -280,19 +280,10 @@ class ParsedCall:
class EventRecorder(object): class EventRecorder(object):
def __init__(self, pyplugins, debug=False): # True): def __init__(self, pyplugins, debug=False): # True):
self.events = []
self.pyplugins = pyplugins self.pyplugins = pyplugins
self.debug = debug self.debug = debug
pyplugins.register(self) pyplugins.register(self)
def popcall(self, name):
for i, event in py.builtin.enumerate(self.events):
if event.name == name:
del self.events[i]
eventparser = self._getcallparser(name)
return eventparser(*event.args, **event.kwargs)
raise KeyError("popevent: %r not found in %r" %(name, self.events))
def getcall(self, name): def getcall(self, name):
l = self.getcalls(name) l = self.getcalls(name)
assert len(l) == 1, (name, l) assert len(l) == 1, (name, l)
@ -308,26 +299,8 @@ class EventRecorder(object):
name = "pytest_" + name name = "pytest_" + name
if self.callrecorder.recordsmethod(name): if self.callrecorder.recordsmethod(name):
l.extend(self.callrecorder.getcalls(name)) l.extend(self.callrecorder.getcalls(name))
else:
for event in self.events:
if event.name == name:
method = self._getcallparser(event.name)
pevent = method(*event.args, **event.kwargs)
l.append(pevent)
return l return l
def _getcallparser(self, eventname):
mname = "pyevent__" + eventname
method = getattr(api.Events, mname)
args, varargs, varkw, default = inspect.getargspec(method)
assert args[0] == "self"
args = args[1:]
fspec = inspect.formatargspec(args, varargs, varkw, default)
code = py.code.compile("""def %(mname)s%(fspec)s:
return ParsedCall(locals())""" % locals())
exec code
return locals()[mname]
# functionality for test reports # functionality for test reports
def getreports(self, names="itemtestreport collectreport"): def getreports(self, names="itemtestreport collectreport"):
@ -384,7 +357,6 @@ class EventRecorder(object):
assert failed == len(realfailed) assert failed == len(realfailed)
def clear(self): def clear(self):
self.events[:] = []
self.callrecorder.calls[:] = [] self.callrecorder.calls[:] = []
def unregister(self): def unregister(self):
@ -424,7 +396,6 @@ def test_eventrecorder(testdir):
recorder.unregister() recorder.unregister()
recorder.clear() recorder.clear()
assert not recorder.events
assert not recorder.getfailures() assert not recorder.getfailures()
bus.call_each("pytest_itemtestreport", rep=rep) bus.call_each("pytest_itemtestreport", rep=rep)
assert not recorder.getfailures() assert not recorder.getfailures()

View File

@ -10,7 +10,7 @@ class Test_genitems:
pass pass
""") """)
p.copy(p.dirpath(p.purebasename + "2" + ".py")) p.copy(p.dirpath(p.purebasename + "2" + ".py"))
items, events = testdir.inline_genitems(p.dirpath()) items, sorter = testdir.inline_genitems(p.dirpath())
assert len(items) == 4 assert len(items) == 4
for numi, i in enumerate(items): for numi, i in enumerate(items):
for numj, j in enumerate(items): for numj, j in enumerate(items):
@ -27,8 +27,8 @@ class Test_genitems:
def test_subdir_conftest_error(self, testdir): def test_subdir_conftest_error(self, testdir):
tmp = testdir.tmpdir tmp = testdir.tmpdir
tmp.ensure("sub", "conftest.py").write("raise SyntaxError\n") tmp.ensure("sub", "conftest.py").write("raise SyntaxError\n")
items, events = testdir.inline_genitems(tmp) items, sorter = testdir.inline_genitems(tmp)
collectionfailures = events.getfailedcollections() collectionfailures = sorter.getfailedcollections()
assert len(collectionfailures) == 1 assert len(collectionfailures) == 1
ev = collectionfailures[0] ev = collectionfailures[0]
assert ev.longrepr.reprcrash.message.startswith("SyntaxError") assert ev.longrepr.reprcrash.message.startswith("SyntaxError")
@ -45,7 +45,7 @@ class Test_genitems:
class TestY(TestX): class TestY(TestX):
pass pass
''') ''')
items, events = testdir.inline_genitems(p) items, sorter = testdir.inline_genitems(p)
assert len(items) == 3 assert len(items) == 3
assert items[0].name == 'testone' assert items[0].name == 'testone'
assert items[1].name == 'testmethod_one' assert items[1].name == 'testmethod_one'

View File

@ -216,7 +216,7 @@ class TestGenerator:
yield list_append_2 yield list_append_2
yield assert_order_of_execution yield assert_order_of_execution
""") """)
sorter = testdir.inline_run(o) # .events_from_cmdline([o]) sorter = testdir.inline_run(o)
passed, skipped, failed = sorter.countoutcomes() passed, skipped, failed = sorter.countoutcomes()
assert passed == 4 assert passed == 4
assert not skipped and not failed assert not skipped and not failed