[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testIToIRegistry.py:1.1.2.4

Jim Fulton jim@zope.com
Wed, 28 Nov 2001 16:54:18 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv21177

Modified Files:
      Tag: Zope-3x-branch
	testIToIRegistry.py 
Log Message:
Updated registration APIs to check for errors. Had to update the tests
to be more careful.


=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testIToIRegistry.py 1.1.2.3 => 1.1.2.4 ===
 
 import unittest, sys
+from Zope.ComponentArchitecture.IToIRegistry import IToIRegistry, IRegistry
+from Interface import Interface
 
 class Test(unittest.TestCase):
 
     def testItAll(self):
         # shane's tests
 
-        import Interface
-        from Zope.ComponentArchitecture.IToIRegistry import IToIRegistry
 
-        class I1(Interface.Base): pass
+        class I1(Interface): pass
         class I2(I1): pass
         class I3(I2): pass
         class I4(I3): pass
@@ -30,35 +30,47 @@
         class A4(NamedClass): __implements__ = I4  # Adapts I1, I2, I3, or I4
         class A6(NamedClass): __implements__ = I6  # Adapts I1 through I6
 
-        class RequiredInterface (Interface.Base): pass
+        class RequiredInterface (Interface): pass
         class InputI (RequiredInterface): pass
 
         reg = IToIRegistry()
-        reg.register(RequiredInterface, I2, A2())
-        reg.register(RequiredInterface, I4, A4())
-        reg.register(RequiredInterface, I6, A6())
-
-        assert reg.get(InputI, I1).name() == 'A2'
-        assert reg.get(InputI, I2).name() == 'A2'
-        assert reg.get(InputI, I3).name() == 'A4'
-        assert reg.get(InputI, I4).name() == 'A4'
-        assert reg.get(InputI, I5).name() == 'A6'
-        assert reg.get(InputI, I6).name() == 'A6'
+        reg.register(RequiredInterface, I2, A2)
+        reg.register(RequiredInterface, I4, A4)
+        reg.register(RequiredInterface, I6, A6)
+
+        assert reg.get(InputI, I1)().name() == 'A2'
+        assert reg.get(InputI, I2)().name() == 'A2'
+        assert reg.get(InputI, I3)().name() == 'A4'
+        assert reg.get(InputI, I4)().name() == 'A4'
+        assert reg.get(InputI, I5)().name() == 'A6'
+        assert reg.get(InputI, I6)().name() == 'A6'
 
         # Be sure that it doesn't matter in what order you register
         # non-conflicting adapters.
         reg = IToIRegistry()
-        reg.register(RequiredInterface, I6, A6())
-        reg.register(RequiredInterface, I4, A4())
-        reg.register(RequiredInterface, I2, A2())
-
-        assert reg.get(InputI, I1).name() == 'A2'
-        assert reg.get(InputI, I2).name() == 'A2'
-        assert reg.get(InputI, I3).name() == 'A4'
-        assert reg.get(InputI, I4).name() == 'A4'
-        assert reg.get(InputI, I5).name() == 'A6'
-        assert reg.get(InputI, I6).name() == 'A6'
+        reg.register(RequiredInterface, I6, A6)
+        reg.register(RequiredInterface, I4, A4)
+        reg.register(RequiredInterface, I2, A2)
+
+        assert reg.get(InputI, I1)().name() == 'A2'
+        assert reg.get(InputI, I2)().name() == 'A2'
+        assert reg.get(InputI, I3)().name() == 'A4'
+        assert reg.get(InputI, I4)().name() == 'A4'
+        assert reg.get(InputI, I5)().name() == 'A6'
+        assert reg.get(InputI, I6)().name() == 'A6'
+
+    def testBadIndirectRegistry(self):
         
+        reg = IToIRegistry()
+        class I1(Interface): pass
+        class I2(Interface): pass
+        self.assertRaises(TypeError, reg.register, I1, I2, None)
+
+    def testBadDirect(self):
+        reg = IRegistry()
+        from Zope.ComponentArchitecture.Exceptions import Invalid
+        class I2(Interface): pass
+        self.assertRaises(Invalid, reg.register, I2, None)
 
 def test_suite():
     loader=unittest.TestLoader()