[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
class TestExecnetEvents:
def test_popengateway_events(self, _pytest):
def test_popengateway(self, _pytest):
rec = _pytest.getcallrecorder(ExecnetAPI)
gw = py.execnet.PopenGateway()
call = rec.popcall("pyexecnet_gateway_init")

View File

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

View File

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

View File

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

View File

@ -280,19 +280,10 @@ class ParsedCall:
class EventRecorder(object):
def __init__(self, pyplugins, debug=False): # True):
self.events = []
self.pyplugins = pyplugins
self.debug = debug
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):
l = self.getcalls(name)
assert len(l) == 1, (name, l)
@ -308,26 +299,8 @@ class EventRecorder(object):
name = "pytest_" + name
if self.callrecorder.recordsmethod(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
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
def getreports(self, names="itemtestreport collectreport"):
@ -384,7 +357,6 @@ class EventRecorder(object):
assert failed == len(realfailed)
def clear(self):
self.events[:] = []
self.callrecorder.calls[:] = []
def unregister(self):
@ -424,7 +396,6 @@ def test_eventrecorder(testdir):
recorder.unregister()
recorder.clear()
assert not recorder.events
assert not recorder.getfailures()
bus.call_each("pytest_itemtestreport", rep=rep)
assert not recorder.getfailures()

View File

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

View File

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