From 92e354a486024c03d7829c283b3cb79cdffff838 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 26 Mar 2009 10:26:09 +0100 Subject: [PATCH] [svn r63339] undo rev 63000 so that there is only one method now for funcargs --HG-- branch : trunk --- py/test/config.py | 19 +------------------ py/test/plugin/pytest_monkeypatch.py | 5 +---- py/test/plugin/pytest_pytester.py | 17 +++++++++-------- py/test/pycollect.py | 13 +++---------- py/test/testing/test_config.py | 28 ---------------------------- 5 files changed, 14 insertions(+), 68 deletions(-) diff --git a/py/test/config.py b/py/test/config.py index 565b019dd..e33ae08de 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -41,7 +41,6 @@ class Config(object): self.pytestplugins = pytestplugins self._conftest = Conftest(onimport=self._onimportconftest) self._setupstate = SetupState() - self._funcarg2maker = {} def _onimportconftest(self, conftestmodule): self.trace("loaded conftestmodule %r" %(conftestmodule,)) @@ -286,23 +285,7 @@ class Config(object): roots.append(pydir) return roots - def register_funcargmaker(self, argname, maker): - """ register a setup method for the given argument name. """ - self._funcarg2maker.setdefault(argname, []).append(maker) - - def _makefuncarg(self, argname, pyfuncitem): - makerlist = self._getmakerlist(argname) - mcall = py._com.MultiCall(makerlist, pyfuncitem) - return mcall.execute(firstresult=True) - - def _getmakerlist(self, argname): - makerlist = self._funcarg2maker.get(argname, None) - if makerlist is None: - msg = "funcarg %r not registered, available are: %s" % ( - argname, ", ".join(self._funcarg2maker.keys())) - raise KeyError(msg) - assert makerlist - return makerlist[:] + # # helpers # diff --git a/py/test/plugin/pytest_monkeypatch.py b/py/test/plugin/pytest_monkeypatch.py index f6a518eb6..50e2fbd51 100644 --- a/py/test/plugin/pytest_monkeypatch.py +++ b/py/test/plugin/pytest_monkeypatch.py @@ -2,10 +2,7 @@ import os class MonkeypatchPlugin: """ setattr-monkeypatching with automatical reversal after test. """ - def pytest_configure(self, config): - config.register_funcargmaker("monkeypatch", self.argmaker) - - def argmaker(self, pyfuncitem): + def pytest_funcarg_monkeypatch(self, pyfuncitem): monkeypatch = MonkeyPatch() pyfuncitem.addfinalizer(monkeypatch.finalize) return monkeypatch diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index d4f18a3ef..3d72f197d 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -7,20 +7,21 @@ from py.__.test import event from py.__.test.config import Config as pytestConfig class PytesterPlugin: - def pytest_configure(self, config): - config.register_funcargmaker("linecomp", lambda x: LineComp()) - config.register_funcargmaker("LineMatcher", lambda x: LineMatcher) - config.register_funcargmaker("EventRecorder", lambda x: EventRecorder) + def pytest_funcarg_linecomp(self, pyfuncitem): + return LineComp() - config.register_funcargmaker("testdir", self.maketestdir) - config.register_funcargmaker("eventrecorder", self.makeeventrecorder) + def pytest_funcarg_LineMatcher(self, pyfuncitem): + return LineMatcher - def maketestdir(self, pyfuncitem): + def pytest_funcarg_testdir(self, pyfuncitem): tmptestdir = TmpTestdir(pyfuncitem) pyfuncitem.addfinalizer(tmptestdir.finalize) return tmptestdir - def makeeventrecorder(self, pyfuncitem): + def pytest_funcarg_EventRecorder(self, pyfuncitem): + return EventRecorder + + def pytest_funcarg_eventrecorder(self, pyfuncitem): evrec = EventRecorder(py._com.pyplugins) pyfuncitem.addfinalizer(lambda: evrec.pyplugins.unregister(evrec)) return evrec diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 12e2f4f7b..3e346aa91 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -371,20 +371,13 @@ class Function(FunctionMixin, py.test.collect.Item): else: raise else: - pass # XXX lookup of arguments for yielded/generated tests as well + pass # XXX lookup of arguments for yielded/generated tests as well ? return kwargs def lookup_onearg(self, argname): prefix = "pytest_funcarg_" - try: - makerlist = self.config._getmakerlist(argname) - except KeyError: - makerlist = [] - l = self.config.pytestplugins.listattr(prefix + argname) - makerlist.extend(l) - mc = py._com.MultiCall(makerlist, self) - #print "mc.methods", mc.methods - value = mc.execute(firstresult=True) + #makerlist = self.config.pytestplugins.listattr(prefix + argname) + value = self.config.pytestplugins.call_firstresult(prefix + argname, pyfuncitem=self) if value is not None: return value else: diff --git a/py/test/testing/test_config.py b/py/test/testing/test_config.py index bee463fc9..25f410d99 100644 --- a/py/test/testing/test_config.py +++ b/py/test/testing/test_config.py @@ -1,33 +1,5 @@ import py -class TestFuncArgsSetup: - def test_register_funcarg_simple(self, testdir): - item = testdir.getitem("def test_func(hello): pass") - def maker(pyfuncitem): - assert item == pyfuncitem - return 42 - item.config.register_funcargmaker("hello", maker) - arg = item.config._makefuncarg("hello", item) - assert arg == 42 - - def test_register_funcarg_two(self, testdir): - item = testdir.getitem("def test_func(hello): pass") - def maker1(pyfuncitem): - assert item == pyfuncitem - return 1 - def maker2(__call__, pyfuncitem): - assert item == pyfuncitem - res = __call__.execute(firstresult=True) - return res + 1 - item.config.register_funcargmaker("two", maker1) - item.config.register_funcargmaker("two", maker2) - arg = item.config._makefuncarg("two", item) - assert arg == 2 - - def test_register_funcarg_error(self, testdir): - item = testdir.getitem("def test_func(hello): pass") - config = item.config - py.test.raises(KeyError, 'item.config._makefuncarg("notexist", item)') class TestConfigCmdlineParsing: def test_config_cmdline_options(self, testdir):