[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_interfacefield.py:1.3

Steve Alexander steve@cat-box.net
Mon, 30 Dec 2002 13:43:37 -0500


Update of /cvs-repository/Zope3/src/zope/app/component/tests
In directory cvs.zope.org:/tmp/cvs-serv29407/src/zope/app/component/tests

Modified Files:
	test_interfacefield.py 
Log Message:
Implemented InterfacesField to select several interfaces.
Refined the query interfaces.


=== Zope3/src/zope/app/component/tests/test_interfacefield.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/component/tests/test_interfacefield.py:1.2	Wed Dec 25 09:12:46 2002
+++ Zope3/src/zope/app/component/tests/test_interfacefield.py	Mon Dec 30 13:43:05 2002
@@ -19,10 +19,10 @@
 from unittest import TestCase, TestSuite, main, makeSuite
 from zope.interface import Interface
 import zope.interface as InterfaceModule
-from zope.app.component.interfacefield import InterfaceField
+from zope.app.component.interfacefield import InterfaceField, InterfacesField
 from zope.schema.interfaces import ValidationError
 
-class Test(TestCase):
+class TestInterfaceField(TestCase):
 
     def test_validate(self):
         field = InterfaceField()
@@ -49,8 +49,38 @@
         self.assertRaises(ValidationError, field.validate, Interface)
         self.assertRaises(ValidationError, field.validate, I1)
 
+class TestInterfacesField(TestCase):
+
+    def test_validate(self):
+        field = InterfacesField()
+        field.validate(())
+        field.validate((Interface,))
+        class I(Interface): pass
+        field.validate((I,))
+
+        self.assertRaises(ValidationError, field.validate, (InterfaceModule,))
+        class I: pass
+        self.assertRaises(ValidationError, field.validate, (I,))
+
+    def test_validate_w_type(self):
+
+        class I1(Interface): pass
+        class I2(I1): pass
+        class I3(I2): pass
+
+        field = InterfacesField(value_type=I2)
+
+        field.validate((I2,))
+        field.validate((I3,))
+
+        self.assertRaises(ValidationError, field.validate, (Interface,))
+        self.assertRaises(ValidationError, field.validate, (I1,))
+
+
 def test_suite():
-    return TestSuite((makeSuite(Test),))
+    return TestSuite((makeSuite(TestInterfaceField),
+                      makeSuite(TestInterfacesField),
+                    ))
 
 if __name__=='__main__':
     main(defaultTest='test_suite')