[Zodb-checkins] CVS: Zope3/src/zope/interface/tests - test_type.py:1.4

Steve Alexander steve@cat-box.net
Thu, 30 Jan 2003 08:38:46 -0500


Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv20711/tests

Modified Files:
	test_type.py 
Log Message:
added getTypesMatching() method to TypeRegistry.


=== Zope3/src/zope/interface/tests/test_type.py 1.3 => 1.4 ===
--- Zope3/src/zope/interface/tests/test_type.py:1.3	Wed Jan 29 13:48:54 2003
+++ Zope3/src/zope/interface/tests/test_type.py	Thu Jan 30 08:38:43 2003
@@ -26,6 +26,11 @@
     all.sort()
     return all
 
+def getTypesMatching(reg, interface):
+    all = list(reg.getTypesMatching(interface))
+    all.sort()
+    return all
+
 class TestTypeRegistry(unittest.TestCase):
 
     def new_instance(self):
@@ -37,7 +42,13 @@
         class I3(I2): pass
 
         reg = self.new_instance()
+
         reg.register(I2, 2)
+        self.assertEqual(getTypesMatching(reg, None), [I2])
+        self.assertEqual(getTypesMatching(reg, Interface), [I2])
+        self.assertEqual(getTypesMatching(reg, I1), [I2])
+        self.assertEqual(getTypesMatching(reg, I2), [I2])
+        self.assertEqual(getTypesMatching(reg, I3), [])
 
         class C1: __implements__ = I1
         class C2: __implements__ = I2
@@ -54,6 +65,11 @@
         self.assertEqual(reg.get(I3), None)
 
         reg.register(I1, 1)
+        self.assertEqual(getTypesMatching(reg, None), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, I1), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, I2), [I2])
+        self.assertEqual(getTypesMatching(reg, I3), [])
 
         self.assertEqual(getAllForObject(reg, C1()), [1])
         self.assertEqual(getAllForObject(reg, C2()), [1, 2])
@@ -65,6 +81,11 @@
         self.assertEqual(reg.get(I3), None)
 
         reg.register(I3, 3)
+        self.assertEqual(getTypesMatching(reg, None), [I1, I2, I3])
+        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2, I3])
+        self.assertEqual(getTypesMatching(reg, I1), [I1, I2, I3])
+        self.assertEqual(getTypesMatching(reg, I2), [I2, I3])
+        self.assertEqual(getTypesMatching(reg, I3), [I3])
 
         self.assertEqual(getAllForObject(reg, C1()), [1])
         self.assertEqual(getAllForObject(reg, C2()), [1, 2])
@@ -76,7 +97,12 @@
         self.assertEqual(reg.get(I3), 3)
 
         reg.unregister(I3)
-        
+        self.assertEqual(getTypesMatching(reg, None), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, I1), [I1, I2])
+        self.assertEqual(getTypesMatching(reg, I2), [I2])
+        self.assertEqual(getTypesMatching(reg, I3), [])
+
         self.assertEqual(getAllForObject(reg, C1()), [1])
         self.assertEqual(getAllForObject(reg, C2()), [1, 2])
         self.assertEqual(getAllForObject(reg, C3()), [1, 2])
@@ -124,7 +150,7 @@
         self.assertRaises(TypeError, registry.register, 42, '')
 
 def test_suite():
-    loader=unittest.TestLoader()
+    loader = unittest.TestLoader()
     return loader.loadTestsFromTestCase(TestTypeRegistry)
 
 if __name__=='__main__':