remove superflous registry.call_firstresult and NONEASFIRSTRESULT logic

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-20 22:02:08 +02:00
parent 4784046249
commit 219e627f87
5 changed files with 11 additions and 59 deletions

View File

@ -10,7 +10,6 @@ class MultiCall:
Simple example:
MultiCall([list1.append, list2.append], 42).execute()
"""
NONEASRESULT = object()
def __init__(self, methods, *args, **kwargs):
self.methods = methods[:]
@ -26,8 +25,6 @@ class MultiCall:
self.results = [res]
break
if res is not None:
if res is self.NONEASRESULT:
res = None
self.results.append(res)
if firstresult:
break
@ -99,15 +96,6 @@ class Registry:
l.reverse()
return l
def call_firstresult(self, methname, *args, **kwargs):
""" return first non-None result of a plugin method. """
return MultiCall(self.listattr(methname), *args, **kwargs).execute(firstresult=True)
def call_plugin(self, plugin, methname, *args, **kwargs):
return MultiCall(self.listattr(methname, plugins=[plugin]),
*args, **kwargs).execute(firstresult=True)
class Hooks:
def __init__(self, hookspecs, registry=None):
self._hookspecs = hookspecs

View File

@ -73,7 +73,15 @@ class TestMultiCall:
# we might not have had a chance to run at all.
#res = call.execute(firstresult=True)
#assert res == 10
def test_call_none_is_no_result(self):
def m1():
return 1
def m2():
return None
mc = MultiCall([m1, m2])
res = mc.execute(firstresult=True)
assert res == 1
class TestRegistry:
def test_MultiCall(self):
@ -97,28 +105,6 @@ class TestRegistry:
assert not registry.isregistered(my)
assert list(registry) == [my2]
def test_call_none_is_no_result(self):
plugins = Registry()
class api1:
def m(self):
return None
class api2:
def m(self, __call__):
return 41
plugins.register(api1())
plugins.register(api1())
plugins.register(api2())
assert plugins.call_firstresult('m') == 41
def test_call_noneasresult(self):
plugins = Registry()
class api1:
def m(self, __call__):
return __call__.NONEASRESULT
plugins.register(api1())
plugins.register(api1())
assert plugins.call_firstresult('m') is None
def test_listattr(self):
plugins = Registry()
class api1:

View File

@ -68,6 +68,7 @@ class PluginHooks:
#
def pytest_itemrun(self, item, pdb=None):
""" run given test item and return test report. """
pytest_itemrun.firstresult = True
def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
""" return True if we consumed/did the call to the python function item. """

View File

@ -108,9 +108,6 @@ class PluginManager(object):
def listattr(self, attrname, plugins=None, extra=()):
return self.comregistry.listattr(attrname, plugins=plugins, extra=extra)
def call_firstresult(self, *args, **kwargs):
return self.comregistry.call_firstresult(*args, **kwargs)
def notify_exception(self, excinfo=None):
if excinfo is None:
excinfo = py.code.ExceptionInfo()
@ -144,7 +141,7 @@ class PluginManager(object):
config.pluginmanager.unregister(self)
def do_itemrun(self, item, pdb=None):
res = self.comregistry.call_firstresult("pytest_itemrun", item=item, pdb=pdb)
res = self.hook.pytest_itemrun(item=item, pdb=pdb)
if res is None:
raise ValueError("could not run %r" %(item,))

View File

@ -191,26 +191,6 @@ class TestPytestPluginInteractions:
assert pluginmanager.getfirst("x") == 1
def test_call_firstresult(self):
pluginmanager = PluginManager()
class My1:
def method(self):
pass
class My2:
def method(self):
return True
class My3:
def method(self):
return None
assert pluginmanager.call_firstresult("method") is None
assert pluginmanager.call_firstresult("methodnotexists") is None
pluginmanager.register(My1())
assert pluginmanager.call_firstresult("method") is None
pluginmanager.register(My2())
assert pluginmanager.call_firstresult("method") == True
pluginmanager.register(My3())
assert pluginmanager.call_firstresult("method") == True
def test_listattr(self):
pluginmanager = PluginManager()
class My2: