From 7ac5aa82a7e67cd82744976315b93a9d660f9ad3 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 28 Nov 2009 19:27:47 +0000 Subject: Deal with registries we may not understand. --- repoze/bfg/testing.py | 8 ++++++-- repoze/bfg/tests/test_testing.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py index 1859cf9b8..9cba616a7 100644 --- a/repoze/bfg/testing.py +++ b/repoze/bfg/testing.py @@ -531,7 +531,7 @@ def setUp(registry=None, request=None, hook_zca=True): .. note:: The ``setUp`` function is new as of :mod:`repoze.bfg` 1.1. - Use this function in the ``setUp`` method of a unit test test case + Use this function in the ``setUp`` method of a unittest test case which directly or indirectly uses: - any of the ``register*`` functions in ``repoze.bfg.testing`` @@ -621,7 +621,11 @@ def tearDown(unhook_zca=True): if info is not None: reg = info['registry'] if hasattr(reg, '__init__') and hasattr(reg, '__name__'): - reg.__init__(reg.__name__) + try: + reg.__init__(reg.__name__) + except TypeError: + # maybe somebody's using a registry we don't understand + pass _clearContext() # XXX why? def cleanUp(*arg, **kw): diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py index 6341825ef..0a9da3e85 100644 --- a/repoze/bfg/tests/test_testing.py +++ b/repoze/bfg/tests/test_testing.py @@ -614,6 +614,23 @@ class Test_tearDown(unittest.TestCase): getSiteManager.reset() manager.clear() + def test_registry_cannot_be_inited(self): + from repoze.bfg.threadlocal import manager + registry = DummyRegistry() + def raiseit(name): + raise TypeError + registry.__init__ = raiseit + old = {'registry':registry} + hook = lambda *arg: None + try: + manager.push(old) + self._callFUT() # doesn't blow up + current = manager.get() + self.assertNotEqual(current, old) + self.assertEqual(registry.inited, 1) + finally: + manager.clear() + def test_unhook_zc_false(self): from repoze.bfg.threadlocal import manager from zope.component import getSiteManager -- cgit v1.2.3