[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._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
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue