From cd322bd528968a2d490041c6ce81e41f2bc526f2 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 9 Apr 2009 02:45:46 +0200 Subject: [PATCH] [svn r63889] renaming/streamlining missing event usage --HG-- branch : trunk --- py/execnet/testing/test_event.py | 2 +- py/test/dist/testing/test_dsession.py | 2 +- py/test/plugin/api.py | 3 ++- py/test/plugin/pytest_doctest.py | 4 +--- py/test/plugin/pytest_pytester.py | 29 --------------------------- py/test/testing/test_genitems.py | 8 ++++---- py/test/testing/test_pycollect.py | 2 +- 7 files changed, 10 insertions(+), 40 deletions(-) diff --git a/py/execnet/testing/test_event.py b/py/execnet/testing/test_event.py index bc4b9fcc8..27da49141 100644 --- a/py/execnet/testing/test_event.py +++ b/py/execnet/testing/test_event.py @@ -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") diff --git a/py/test/dist/testing/test_dsession.py b/py/test/dist/testing/test_dsession.py index 40acd4a46..9af7c498e 100644 --- a/py/test/dist/testing/test_dsession.py +++ b/py/test/dist/testing/test_dsession.py @@ -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() diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index 987c8a5e0..c3f709e60 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -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. """ diff --git a/py/test/plugin/pytest_doctest.py b/py/test/plugin/pytest_doctest.py index 13a23b7dc..131fdc2f3 100644 --- a/py/test/plugin/pytest_doctest.py +++ b/py/test/plugin/pytest_doctest.py @@ -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) diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 6dc759976..703cec614 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -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() diff --git a/py/test/testing/test_genitems.py b/py/test/testing/test_genitems.py index a51a79451..632e54732 100644 --- a/py/test/testing/test_genitems.py +++ b/py/test/testing/test_genitems.py @@ -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' diff --git a/py/test/testing/test_pycollect.py b/py/test/testing/test_pycollect.py index 1f4fad79b..74b03ab4e 100644 --- a/py/test/testing/test_pycollect.py +++ b/py/test/testing/test_pycollect.py @@ -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