[svn r63339] undo rev 63000 so that there is only one method now for funcargs
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									8230a39b39
								
							
						
					
					
						commit
						92e354a486
					
				| 
						 | 
					@ -41,7 +41,6 @@ class Config(object):
 | 
				
			||||||
        self.pytestplugins = pytestplugins
 | 
					        self.pytestplugins = pytestplugins
 | 
				
			||||||
        self._conftest = Conftest(onimport=self._onimportconftest)
 | 
					        self._conftest = Conftest(onimport=self._onimportconftest)
 | 
				
			||||||
        self._setupstate = SetupState() 
 | 
					        self._setupstate = SetupState() 
 | 
				
			||||||
        self._funcarg2maker = {}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _onimportconftest(self, conftestmodule):
 | 
					    def _onimportconftest(self, conftestmodule):
 | 
				
			||||||
        self.trace("loaded conftestmodule %r" %(conftestmodule,))
 | 
					        self.trace("loaded conftestmodule %r" %(conftestmodule,))
 | 
				
			||||||
| 
						 | 
					@ -286,23 +285,7 @@ class Config(object):
 | 
				
			||||||
            roots.append(pydir)
 | 
					            roots.append(pydir)
 | 
				
			||||||
        return roots 
 | 
					        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
 | 
					# helpers
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,10 +2,7 @@ import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MonkeypatchPlugin:
 | 
					class MonkeypatchPlugin:
 | 
				
			||||||
    """ setattr-monkeypatching with automatical reversal after test. """
 | 
					    """ setattr-monkeypatching with automatical reversal after test. """
 | 
				
			||||||
    def pytest_configure(self, config):
 | 
					    def pytest_funcarg_monkeypatch(self, pyfuncitem):
 | 
				
			||||||
        config.register_funcargmaker("monkeypatch", self.argmaker)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def argmaker(self, pyfuncitem):
 | 
					 | 
				
			||||||
        monkeypatch = MonkeyPatch()
 | 
					        monkeypatch = MonkeyPatch()
 | 
				
			||||||
        pyfuncitem.addfinalizer(monkeypatch.finalize)
 | 
					        pyfuncitem.addfinalizer(monkeypatch.finalize)
 | 
				
			||||||
        return monkeypatch
 | 
					        return monkeypatch
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,20 +7,21 @@ from py.__.test import event
 | 
				
			||||||
from py.__.test.config import Config as pytestConfig
 | 
					from py.__.test.config import Config as pytestConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PytesterPlugin:
 | 
					class PytesterPlugin:
 | 
				
			||||||
    def pytest_configure(self, config):
 | 
					    def pytest_funcarg_linecomp(self, pyfuncitem):
 | 
				
			||||||
        config.register_funcargmaker("linecomp", lambda x: LineComp())
 | 
					        return LineComp()
 | 
				
			||||||
        config.register_funcargmaker("LineMatcher", lambda x: LineMatcher)
 | 
					 | 
				
			||||||
        config.register_funcargmaker("EventRecorder", lambda x: EventRecorder)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        config.register_funcargmaker("testdir", self.maketestdir)
 | 
					    def pytest_funcarg_LineMatcher(self, pyfuncitem):
 | 
				
			||||||
        config.register_funcargmaker("eventrecorder", self.makeeventrecorder)
 | 
					        return LineMatcher
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def maketestdir(self, pyfuncitem):
 | 
					    def pytest_funcarg_testdir(self, pyfuncitem):
 | 
				
			||||||
        tmptestdir = TmpTestdir(pyfuncitem)
 | 
					        tmptestdir = TmpTestdir(pyfuncitem)
 | 
				
			||||||
        pyfuncitem.addfinalizer(tmptestdir.finalize)
 | 
					        pyfuncitem.addfinalizer(tmptestdir.finalize)
 | 
				
			||||||
        return tmptestdir
 | 
					        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)
 | 
					        evrec = EventRecorder(py._com.pyplugins)
 | 
				
			||||||
        pyfuncitem.addfinalizer(lambda: evrec.pyplugins.unregister(evrec))
 | 
					        pyfuncitem.addfinalizer(lambda: evrec.pyplugins.unregister(evrec))
 | 
				
			||||||
        return evrec
 | 
					        return evrec
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -371,20 +371,13 @@ class Function(FunctionMixin, py.test.collect.Item):
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        raise
 | 
					                        raise
 | 
				
			||||||
        else:
 | 
					        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
 | 
					        return kwargs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def lookup_onearg(self, argname):
 | 
					    def lookup_onearg(self, argname):
 | 
				
			||||||
        prefix = "pytest_funcarg_"
 | 
					        prefix = "pytest_funcarg_"
 | 
				
			||||||
        try:
 | 
					        #makerlist = self.config.pytestplugins.listattr(prefix + argname)
 | 
				
			||||||
            makerlist = self.config._getmakerlist(argname)
 | 
					        value = self.config.pytestplugins.call_firstresult(prefix + argname, pyfuncitem=self)
 | 
				
			||||||
        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)
 | 
					 | 
				
			||||||
        if value is not None:
 | 
					        if value is not None:
 | 
				
			||||||
            return value
 | 
					            return value
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,33 +1,5 @@
 | 
				
			||||||
import py
 | 
					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:
 | 
					class TestConfigCmdlineParsing:
 | 
				
			||||||
    def test_config_cmdline_options(self, testdir):
 | 
					    def test_config_cmdline_options(self, testdir):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue