[Zope-CVS] CVS: Products/Event/tests - testEventRegistry.py:1.4
Chris McDonough
chrism@zope.com
Tue, 3 Jun 2003 14:32:50 -0400
Update of /cvs-repository/Products/Event/tests
In directory cvs.zope.org:/tmp/cvs-serv32510/tests
Modified Files:
testEventRegistry.py
Log Message:
Add new method to event registry: listEventsWhichExtend, which receives an interface. Returned are the keys into the registry for the interfaces which extend the passed in interface.
=== Products/Event/tests/testEventRegistry.py 1.3 => 1.4 ===
--- Products/Event/tests/testEventRegistry.py:1.3 Sat Sep 21 12:31:08 2002
+++ Products/Event/tests/testEventRegistry.py Tue Jun 3 14:32:49 2003
@@ -1,8 +1,29 @@
import unittest
+from Interface import Interface
class DummyEvent:
"""Dummy Event semi-interface."""
+class BaseEventInterface(Interface):
+ """Base"""
+ pass
+
+class Extends1(BaseEventInterface):
+ """Extends1"""
+ pass
+
+class Extends2(BaseEventInterface):
+ """Extends2"""
+ pass
+
+class Extends3(Extends1):
+ """Extends3"""
+ pass
+
+class Extends4(Extends2):
+ """Extends4"""
+ pass
+
class EventRegistryTests(unittest.TestCase):
oldRegistry = None
@@ -57,6 +78,34 @@
self.assertEqual(registry.getEventTitle(key), 'Dummy Event (bar)')
self.assertEqual(registry.getEventDescription(key), 'Bar Description')
self.failUnless(registry.getEventInterface(key) is Bar)
+
+ def test_listEventsWhichExtend(self):
+ registry = self._makeOne()
+ base = BaseEventInterface
+ registry.registerEvent(base, 'Base')
+ registry.registerEvent(Extends1, 'Extends1')
+ registry.registerEvent(Extends2, 'Extends2')
+ registry.registerEvent(Extends3, 'Extends3')
+ registry.registerEvent(Extends4, 'Extends4')
+
+ # test if working
+ for name in ('__main__.Extends1', '__main__.Extends2',
+ '__main__.Extends3', '__main__.Extends4'):
+ self.failUnless(name in registry.listEventsWhichExtend(base))
+
+ # test strictness
+ self.failIf(registry.listEventsWhichExtend(Extends3))
+ self.assertEqual(
+ registry.listEventsWhichExtend(Extends3, strict=0),
+ ['__main__.Extends3']
+ )
+
+ # test metadata
+ self.failUnless(
+ ('__main__.Extends1', 'Extends1', 'Extends1') in
+ registry.listEventsWhichExtend(base, with_metadata=1)
+ )
+
class ReindentDocstringTest(unittest.TestCase):
def _reindent(self, doc):