summaryrefslogtreecommitdiff
path: root/src/zope/interface/tests
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-06-14 08:51:43 -0500
committerJason Madden <jamadden@gmail.com>2017-06-14 08:51:43 -0500
commit751a95088567e4d219ecac6f2145f26b5753e424 (patch)
treeae1305d3c81ddf6dbdc4b7298cc32941084ec54b /src/zope/interface/tests
parentbf0565350d8973f8ba260d0824678248d053de11 (diff)
downloadzope-interface-issue93.tar.gz
Fix the cache getting out of sync with _utility_registrations.issue93
Fixes #93
Diffstat (limited to 'src/zope/interface/tests')
-rw-r--r--src/zope/interface/tests/test_registry.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/zope/interface/tests/test_registry.py b/src/zope/interface/tests/test_registry.py
index dd3cbbe..e5a8eb0 100644
--- a/src/zope/interface/tests/test_registry.py
+++ b/src/zope/interface/tests/test_registry.py
@@ -342,6 +342,59 @@ class ComponentsTests(unittest.TestCase):
comp.registerUtility(_to_reg, ifoo, _name, _info, False)
self.assertEqual(len(_events), 0)
+ def test_registerUtility_changes_object_identity_after(self):
+ # If a subclass changes the identity of the _utility_registrations,
+ # the cache is updated and the right thing still happens.
+ class CompThatChangesAfter1Reg(self._getTargetClass()):
+ reg_count = 0
+ def registerUtility(self, *args):
+ self.reg_count += 1
+ super(CompThatChangesAfter1Reg, self).registerUtility(*args)
+ if self.reg_count == 1:
+ self._utility_registrations = dict(self._utility_registrations)
+
+ comp = CompThatChangesAfter1Reg()
+ comp.registerUtility(object(), Interface)
+
+ self.assertEqual(len(list(comp.registeredUtilities())), 1)
+
+ class IFoo(Interface):
+ pass
+
+ comp.registerUtility(object(), IFoo)
+ self.assertEqual(len(list(comp.registeredUtilities())), 2)
+
+ def test_registerUtility_changes_object_identity_before(self):
+ # If a subclass changes the identity of the _utility_registrations,
+ # the cache is updated and the right thing still happens.
+ class CompThatChangesAfter2Reg(self._getTargetClass()):
+ reg_count = 0
+ def registerUtility(self, *args):
+ self.reg_count += 1
+ if self.reg_count == 2:
+ self._utility_registrations = dict(self._utility_registrations)
+
+ super(CompThatChangesAfter2Reg, self).registerUtility(*args)
+
+ comp = CompThatChangesAfter2Reg()
+ comp.registerUtility(object(), Interface)
+
+ self.assertEqual(len(list(comp.registeredUtilities())), 1)
+
+ class IFoo(Interface):
+ pass
+
+ comp.registerUtility(object(), IFoo)
+ self.assertEqual(len(list(comp.registeredUtilities())), 2)
+
+
+ class IBar(Interface):
+ pass
+
+ comp.registerUtility(object(), IBar)
+ self.assertEqual(len(list(comp.registeredUtilities())), 3)
+
+
def test_unregisterUtility_neither_factory_nor_component_nor_provided(self):
comp = self._makeOne()
self.assertRaises(TypeError, comp.unregisterUtility,