[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture/tests - testTypeRegistry.py:1.1.2.3

Jim Fulton jim@zope.com
Fri, 22 Feb 2002 15:37:48 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	testTypeRegistry.py 
Log Message:
Added getAll and getAllForObject to 



=== Zope3/lib/python/Zope/ComponentArchitecture/tests/testTypeRegistry.py 1.1.2.2 => 1.1.2.3 ===
 from Interface import Interface
 
+def getAllForObject(reg, ob):
+    all = list(reg.getAllForObject(ob))
+    all.sort()
+    return all
+
 class Test(CleanUp, unittest.TestCase):
 
     def test(self):
@@ -42,6 +47,11 @@
         self.assertEqual(reg.getForObject(C3()), 2)
         self.assertEqual(reg.getForObject(C()), None)
 
+        self.assertEqual(getAllForObject(reg, C1()), [])
+        self.assertEqual(getAllForObject(reg, C2()), [2])
+        self.assertEqual(getAllForObject(reg, C3()), [2])
+        self.assertEqual(getAllForObject(reg,  C()), [])
+
         self.assertEqual(reg.getForType(I1), None)
         self.assertEqual(reg.getForType(I2), 2)
         self.assertEqual(reg.getForType(I3), 2)
@@ -52,6 +62,11 @@
         self.assertEqual(reg.getForObject(C3()), 2)
         self.assertEqual(reg.getForObject(C()), None)
 
+        self.assertEqual(getAllForObject(reg, C1()), [1])
+        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
+        self.assertEqual(getAllForObject(reg, C3()), [1, 2])
+        self.assertEqual(getAllForObject(reg,  C()), [])
+
         self.assertEqual(reg.getForType(I1), 1)
         self.assertEqual(reg.getForType(I2), 2)
         self.assertEqual(reg.getForType(I3), 2)
@@ -62,9 +77,44 @@
         self.assertEqual(reg.getForObject(C3()), 3)
         self.assertEqual(reg.getForObject(C()), None)
 
+        self.assertEqual(getAllForObject(reg, C1()), [1])
+        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
+        self.assertEqual(getAllForObject(reg, C3()), [1, 2, 3])
+        self.assertEqual(getAllForObject(reg,  C()), [])
+
         self.assertEqual(reg.getForType(I1), 1)
         self.assertEqual(reg.getForType(I2), 2)
         self.assertEqual(reg.getForType(I3), 3)
+
+    def testDup(self):
+        class I1(Interface): pass
+        class I2(I1): pass
+        class I3(I1): pass
+        class I4(I2, I3): pass
+        class C1: __implements__ = I1
+        class C2: __implements__ = I2
+        class C3: __implements__ = I3
+        class C4: __implements__ = I4
+        class C5: __implements__ = I1, I2, I3, I4
+        class C: pass
+
+        reg = TypeRegistry()
+        reg.register(I1, 1)
+        reg.register(I2, 2)
+        reg.register(I3, 3)
+
+        self.assertEqual(reg.getForObject(C1()), 1)
+        self.assertEqual(reg.getForObject(C2()), 2)
+        self.assertEqual(reg.getForObject(C3()), 3)
+        self.failUnless(reg.getForObject(C3()) in (2,3))
+        self.assertEqual(reg.getForObject(C()), None)
+
+        self.assertEqual(getAllForObject(reg, C1()), [1])
+        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
+        self.assertEqual(getAllForObject(reg, C3()), [1, 3])
+        self.assertEqual(getAllForObject(reg, C4()), [1, 2, 3])
+        self.assertEqual(getAllForObject(reg, C5()), [1, 2, 3])
+        self.assertEqual(getAllForObject(reg,  C()), [])
 
 def test_suite():
     loader=unittest.TestLoader()