[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/tests - testInterfaceField.py:1.2.8.1 testInterfaceService.py:1.2.18.1

Jim Fulton jim@zope.com
Thu, 12 Dec 2002 10:12:01 -0500


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

Modified Files:
      Tag: AdapterAndView-branch
	testInterfaceField.py testInterfaceService.py 
Log Message:
- Added an interface directive for registering interfaces directly

- Added a "type" field to interface fields to limit interfaces to
  those that extend a type.

- Changed the provideInterface in the global InterfaceService to
  accept a false id, in which case it computes the id from the
  interface module and name.

- Updated the widget to reflect the changes.



=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceField.py 1.2 => 1.2.8.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceField.py:1.2	Wed Dec  4 04:54:06 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceField.py	Thu Dec 12 10:12:00 2002
@@ -17,22 +17,39 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-import Interface
+from Interface import Interface
+import Interface as InterfaceModule
 from Zope.App.ComponentArchitecture.InterfaceField import InterfaceField
 from Zope.Schema.Exceptions import ValidationError
+
+
         
 class Test(TestCase):
 
     def test_validate(self):
         field = InterfaceField()
         
-        field.validate(Interface.Interface)
-        class I(Interface.Interface): pass
+        field.validate(Interface)
+        class I(Interface): pass
         field.validate(I)
         
-        self.assertRaises(ValidationError, field.validate, Interface)
+        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 = InterfaceField(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),))


=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceService.py 1.2 => 1.2.18.1 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceService.py:1.2	Tue Nov 19 18:15:14 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testInterfaceService.py	Thu Dec 12 10:12:00 2002
@@ -11,15 +11,18 @@
      import serviceManager, defineService
 
 
+class B(Interface):
+    pass
+
 class I(Interface):
     """bah blah
     """
     
-class I2(Interface):
+class I2(B):
     """eek
     """
     
-class I3(Interface):
+class I3(B):
     """
     """
     def one():
@@ -50,6 +53,7 @@
         self.assertEqual(service.getInterface('Foo.Bar'), I)
         self.assertEqual(service.queryInterface('Foo.Bar'), I)
         self.assertEqual(list(service.searchInterface('')), [I])
+        self.assertEqual(list(service.searchInterface(base=B)), [])
 
         service.provideInterface('Foo.Baz', I2)
 
@@ -65,6 +69,11 @@
 
         service.provideInterface('Foo.Bus', I3)
         self.assertEqual(list(service.searchInterface('two')), [I3])
+        self.assertEqual(list(service.searchInterface('two', base=B)), [I3])
+
+        r = list(service.searchInterface(base=B))
+        r.sort()
+        self.assertEqual(r, [I2, I3])
 
 def test_suite():
     return TestSuite((makeSuite(Test),))