[Zodb-checkins] CVS: Zope3/lib/python/Interface/Registry/tests - TestIAdapterRegistry.py:1.2.8.1

K.Narasimha Murthy nmurthy@zeomega.com
Tue, 15 Oct 2002 10:41:31 -0400


Update of /cvs-repository/Zope3/lib/python/Interface/Registry/tests
In directory cvs.zope.org:/tmp/cvs-serv14669/Registry/tests

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	TestIAdapterRegistry.py 
Log Message:
changed  the AdapterRegistry constructer to take in an optional parameter viz: data 
 Added a new getRegistered() method to the IAdapterRegistry and AdapterRegistry`


=== Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py 1.2 => 1.2.8.1 ===
--- Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py:1.2	Thu Aug  1 12:06:41 2002
+++ Zope3/lib/python/Interface/Registry/tests/TestIAdapterRegistry.py	Tue Oct 15 10:41:30 2002
@@ -1,80 +1,94 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""
-
-Revision information:
-$Id$
-"""
-
-from Interface import Interface
-
-class R1(Interface): pass
-class R12(Interface): pass
-class R2(R1): pass
-class R3(R2): pass
-class R4(R3): pass
-
-class P1(Interface): pass
-class P2(P1): pass
-class P3(P2): pass
-class P4(P3): pass
-
-class TestIAdapterRegistry:
-
-    def testImplementsIAdapterRegistry(self):
-        from Interface.Verify import verifyObject
-        from Interface.Registry.IAdapterRegistry import IAdapterRegistry
-        
-        registry = self._TestIAdapterRegistry__new()
-
-        verifyObject(IAdapterRegistry, registry)
-
-    def __registery(self):        
-        registry = self._TestIAdapterRegistry__new()
-
-        registry.register(None, P3, 'default P3')
-        registry.register(Interface, P3, 'any P3')
-        registry.register(R2, P3, 'R2 P3')
-
-        return registry
-
-    def testBadRequire(self):
-        registry = self._TestIAdapterRegistry__new()
-        self.assertRaises(TypeError, registry.register, 42, P3, '')
-
-    def testBadProvide(self):
-        registry = self._TestIAdapterRegistry__new()
-        self.assertRaises(TypeError, registry.register, R2, None, '')
-        
-
-    def test_get(self):
-        registry = self.__registery()
-
-        for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
-            for P in [P1, P2, P3]:
-                self.assertEqual(registry.get((R, P)), 'R2 P3')
-
-        for R in [None, R1, R2, R3, R4, (R12, R2), (R12, R4)]:
-            self.assertEqual(registry.get((R, P4)), None)
-
-        for P in [P1, P2, P3]:
-            self.assertEqual(registry.get((R1, P)), 'any P3')
-
-        for P in [P1, P2, P3]:
-            self.assertEqual(registry.get((None, P)), 'default P3')
-
-        
-        
-        
-
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from Interface import Interface
+
+class R1(Interface): pass
+class R12(Interface): pass
+class R2(R1): pass
+class R3(R2): pass
+class R4(R3): pass
+
+class P1(Interface): pass
+class P2(P1): pass
+class P3(P2): pass
+class P4(P3): pass
+
+class TestIAdapterRegistry:
+
+    def testImplementsIAdapterRegistry(self):
+        from Interface.Verify import verifyObject
+        from Interface.Registry.IAdapterRegistry import IAdapterRegistry
+        
+        registry = self._TestIAdapterRegistry__new()
+
+        verifyObject(IAdapterRegistry, registry)
+
+    def __registery(self):        
+        registry = self._TestIAdapterRegistry__new()
+
+        registry.register(None, P3, 'default P3')
+        registry.register(Interface, P3, 'any P3')
+        registry.register(R2, P3, 'R2 P3')
+
+        return registry
+
+    def testBadRequire(self):
+        registry = self._TestIAdapterRegistry__new()
+        self.assertRaises(TypeError, registry.register, 42, P3, '')
+
+    def testBadProvide(self):
+        registry = self._TestIAdapterRegistry__new()
+        self.assertRaises(TypeError, registry.register, R2, None, '')
+        
+
+    def test_get(self):
+        registry = self.__registery()
+
+        for R in [R2, R3, R4, (R12, R2), (R12, R4)]:
+            for P in [P1, P2, P3]:
+                self.assertEqual(registry.get((R, P)), 'R2 P3')
+
+        for R in [None, R1, R2, R3, R4, (R12, R2), (R12, R4)]:
+            self.assertEqual(registry.get((R, P4)), None)
+
+        for P in [P1, P2, P3]:
+            self.assertEqual(registry.get((R1, P)), 'any P3')
+
+        for P in [P1, P2, P3]:
+            self.assertEqual(registry.get((None, P)), 'default P3')
+
+    def test_getRegistered(self):
+        registry = self.__registery()
+         
+        # Get something that was registered directly
+        self.assertEqual(registry.getRegistered(R2, P3), 'R2 P3')
+        self.assertEqual(registry.getRegistered(Interface, P3), 'any P3')
+        self.assertEqual(registry.getRegistered(None, P3), 'default P3')
+         
+        # this mustn't return anything that was not registered directly
+        self.assertEqual(registry.getRegistered(R3, P3), None)
+        self.assertEqual(registry.getRegistered(R2, P2), None)
+
+         
+
+        
+        
+        
+