From 0f5d8befb0f7a77c3b1ac96e43f9924f512d7fb7 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 4 Aug 2009 17:02:47 +0000 Subject: - Allow ``repoze.bfg.traversal.find_interface`` API to use a class object as the argument to compare against the ``model`` passed in. This means you can now do ``find_interface(model, SomeClass)`` and the first object which is found in the lineage which has ``SomeClass`` as its class (or the first object found which has ``SomeClass`` as any of its superclasses) will be returned. --- repoze/bfg/tests/test_traversal.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 4a4080aab..3041a271c 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -327,7 +327,7 @@ class FindInterfaceTests(unittest.TestCase): from repoze.bfg.traversal import find_interface return find_interface(context, iface) - def test_it(self): + def test_it_interface(self): baz = DummyContext() bar = DummyContext(baz) foo = DummyContext(bar) @@ -349,6 +349,26 @@ class FindInterfaceTests(unittest.TestCase): result = self._callFUT(baz, IFoo) self.assertEqual(result.__name__, 'root') + def test_it_class(self): + class DummyRoot(object): + def __init__(self, child): + self.child = child + baz = DummyContext() + bar = DummyContext(baz) + foo = DummyContext(bar) + root = DummyRoot(foo) + root.__parent__ = None + root.__name__ = 'root' + foo.__parent__ = root + foo.__name__ = 'foo' + bar.__parent__ = foo + bar.__name__ = 'bar' + baz.__parent__ = bar + baz.__name__ = 'baz' + request = DummyRequest() + result = self._callFUT(baz, DummyRoot) + self.assertEqual(result.__name__, 'root') + class FindRootTests(unittest.TestCase): def _callFUT(self, context): from repoze.bfg.traversal import find_root -- cgit v1.2.3