[svn r63911] striking unneeded call_each from pluginmanager

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-09 20:39:59 +02:00
parent f319a84503
commit 73529ce63d
5 changed files with 14 additions and 31 deletions

View File

@ -443,8 +443,7 @@ class Directory(FSCollector):
def consider_dir(self, path, usefilters=None): def consider_dir(self, path, usefilters=None):
if usefilters is not None: if usefilters is not None:
APIWARN("0.99", "usefilters argument not needed") APIWARN("0.99", "usefilters argument not needed")
res = self.config.pluginmanager.call_firstresult( res = self.config.api.pytest_collect_recurse(path=path, parent=self)
'pytest_collect_recurse', path=path, parent=self)
if res is None or res: if res is None or res:
return self.config.api.pytest_collect_directory( return self.config.api.pytest_collect_directory(
path=path, parent=self) path=path, parent=self)

View File

@ -44,6 +44,7 @@ class PluginHooks:
""" return True/False to cause/prevent recursion into given directory. """ return True/False to cause/prevent recursion into given directory.
return None if you do not want to make the decision. return None if you do not want to make the decision.
""" """
pytest_collect_recurse.firstresult = True
def pytest_collect_directory(self, path, parent): def pytest_collect_directory(self, path, parent):
""" return Collection node or None. """ """ return Collection node or None. """

View File

@ -106,7 +106,7 @@ def test_callrecorder_basic():
def xyz(self, arg): def xyz(self, arg):
pass pass
rec.start_recording(ApiClass) rec.start_recording(ApiClass)
comregistry.call_each("xyz", 123) rec.api.xyz(arg=123)
call = rec.popcall("xyz") call = rec.popcall("xyz")
assert call.arg == 123 assert call.arg == 123
assert call._name == "xyz" assert call._name == "xyz"
@ -124,7 +124,7 @@ def test_functional(testdir, linecomp):
def xyz(self, arg): def xyz(self, arg):
return arg + 1 return arg + 1
rec._comregistry.register(Plugin()) rec._comregistry.register(Plugin())
res = rec._comregistry.call_firstresult("xyz", 41) res = rec.api.xyz(arg=41)
assert res == 42 assert res == [42]
""") """)
sorter.assertoutcome(passed=1) sorter.assertoutcome(passed=1)

View File

@ -79,16 +79,12 @@ class PluginManager(object):
for x in self.comregistry.listattr(attrname): for x in self.comregistry.listattr(attrname):
return x return x
def listattr(self, attrname): def listattr(self, attrname, plugins=None):
return self.comregistry.listattr(attrname) return self.comregistry.listattr(attrname, plugins=plugins)
def call_firstresult(self, *args, **kwargs): def call_firstresult(self, *args, **kwargs):
return self.comregistry.call_firstresult(*args, **kwargs) return self.comregistry.call_firstresult(*args, **kwargs)
def call_each(self, *args, **kwargs):
#print "plugins.call_each", args[0], args[1:], kwargs
return self.comregistry.call_each(*args, **kwargs)
def notify_exception(self, excinfo=None): def notify_exception(self, excinfo=None):
if excinfo is None: if excinfo is None:
excinfo = py.code.ExceptionInfo() excinfo = py.code.ExceptionInfo()
@ -102,8 +98,12 @@ class PluginManager(object):
def pytest_plugin_registered(self, plugin): def pytest_plugin_registered(self, plugin):
if hasattr(self, '_config'): if hasattr(self, '_config'):
self.comregistry.call_plugin(plugin, "pytest_addoption", parser=self._config._parser) self.call_plugin(plugin, "pytest_addoption", parser=self._config._parser)
self.comregistry.call_plugin(plugin, "pytest_configure", config=self._config) self.call_plugin(plugin, "pytest_configure", config=self._config)
def call_plugin(self, plugin, methname, **kwargs):
return self.MultiCall(self.listattr(methname, plugins=[plugin]),
**kwargs).execute(firstresult=True)
def do_configure(self, config): def do_configure(self, config):
assert not hasattr(self, '_config') assert not hasattr(self, '_config')

View File

@ -172,12 +172,9 @@ class TestPytestPluginInteractions:
def test_configure(self, testdir): def test_configure(self, testdir):
config = testdir.parseconfig() config = testdir.parseconfig()
l = [] l = []
events = []
class A: class A:
def pytest_configure(self, config): def pytest_configure(self, config):
l.append(self) l.append(self)
def xyz(self, obj):
events.append(obj)
config.pluginmanager.register(A()) config.pluginmanager.register(A())
assert len(l) == 0 assert len(l) == 0
@ -186,11 +183,7 @@ class TestPytestPluginInteractions:
config.pluginmanager.register(A()) # this should lead to a configured() plugin config.pluginmanager.register(A()) # this should lead to a configured() plugin
assert len(l) == 2 assert len(l) == 2
assert l[0] != l[1] assert l[0] != l[1]
config.pluginmanager.call_each("xyz", obj=42)
assert len(events) == 2
assert events == [42,42]
config.pluginmanager.do_unconfigure(config=config) config.pluginmanager.do_unconfigure(config=config)
config.pluginmanager.register(A()) config.pluginmanager.register(A())
assert len(l) == 2 assert len(l) == 2
@ -209,16 +202,6 @@ class TestPytestPluginInteractions:
pluginmanager.register(My1()) pluginmanager.register(My1())
assert pluginmanager.getfirst("x") == 1 assert pluginmanager.getfirst("x") == 1
def test_call_each(self):
pluginmanager = PluginManager()
class My:
def method(self, arg):
pass
pluginmanager.register(My())
py.test.raises(TypeError, 'pluginmanager.call_each("method")')
l = pluginmanager.call_each("method", arg=42)
assert l == []
py.test.raises(TypeError, 'pluginmanager.call_each("method", arg=42, s=13)')
def test_call_firstresult(self): def test_call_firstresult(self):
pluginmanager = PluginManager() pluginmanager = PluginManager()