diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-08-04 17:02:47 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-08-04 17:02:47 +0000 |
| commit | 0f5d8befb0f7a77c3b1ac96e43f9924f512d7fb7 (patch) | |
| tree | 00f4d7cab03cf86cc192906dacc0a8079eebae9b /repoze/bfg/tests | |
| parent | ff65a5a7b6177759191071be8790d02bd4c0ce8e (diff) | |
| download | pyramid-0f5d8befb0f7a77c3b1ac96e43f9924f512d7fb7.tar.gz pyramid-0f5d8befb0f7a77c3b1ac96e43f9924f512d7fb7.tar.bz2 pyramid-0f5d8befb0f7a77c3b1ac96e43f9924f512d7fb7.zip | |
- 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.
Diffstat (limited to 'repoze/bfg/tests')
| -rw-r--r-- | repoze/bfg/tests/test_traversal.py | 22 |
1 files changed, 21 insertions, 1 deletions
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 |
