[Zope-Checkins] CVS: Zope3/lib/python/Interface/tests - testDocument.py:1.5 testInterface.py:1.6

Jim Fulton jim@zope.com
Mon, 1 Jul 2002 14:12:00 -0400


Update of /cvs-repository/Zope3/lib/python/Interface/tests
In directory cvs.zope.org:/tmp/cvs-serv21785/lib/python/Interface/tests

Modified Files:
	testDocument.py testInterface.py 
Log Message:
Added several interface mapping operations and methods: __getitem__,
get, __contains__, and __iter__.

Changed the code to extract metadata from functions to:

  - Use the name assigned in the interface, rather than the name used
    in the function. This is to allow aliasing::

      class I(Interface):
        def f1(blah): pass
        f2 = f1

  - Copy function attributes to tagged values. This will allow us to
    set meta-data for things like optional methods or attributes
    defined by instances rather than classes::

      class I(Interface):
        def f1(blah): pass
        f1.optional = 1 # Want's to be True ;)

Changed pyskel to:

  - Not include doc strings that reference an interface,

  - Not generate comments for interfaces that don't define any names.

  - Generate code to interface-defined doc strings to generated classes and
    their method skeletin. Of course, this won't work with
    documentation tools that parse source. :(

     



=== Zope3/lib/python/Interface/tests/testDocument.py 1.4 => 1.5 ===
  Methods:
 
-  f22() -- no documentation
-
   f21() -- f21 doc
+
+  f22() -- no documentation
 
   f23() -- f23 doc
 


=== Zope3/lib/python/Interface/tests/testInterface.py 1.5 => 1.6 ===
         self.assertRaises(KeyError, _I2.getDescriptionFor, 'f33')
 
+    def test___getitem__(self):
+        self.assertEqual(_I2['f11'].__name__, 'f11')
+        self.assertEqual(_I2['f22'].__name__, 'f22')
+        self.assertEqual(_I2.get('f33', self), self)
+        self.assertRaises(KeyError, _I2.__getitem__, 'f33')
+
+    def test___contains__(self):
+        self.failUnless('f11' in _I2)
+        self.failIf('f33' in _I2)
+
+    def test___iter__(self):
+        names = list(iter(_I2))
+        names.sort()
+        self.assertEqual(names, ['a1', 'f11', 'f12', 'f21', 'f22', 'f23'])
+
     def testAttr(self):
         description = _I2.getDescriptionFor('a1')
         self.assertEqual(description.__name__, 'a1')
         self.assertEqual(description.__doc__, 'This is an attribute')
-    
+
+
+    def testFunctionAttributes(self):
+        """Make sure function attributes become tagged values.
+        """
+
+        meth = _I1['f12']
+        self.assertEqual(meth.getTaggedValue('optional'), 1)
 
 class _I1(Interface):
 
@@ -127,6 +149,7 @@
     
     def f11(): pass
     def f12(): pass
+    f12.optional = 1
 
 class _I1_(_I1): pass
 class _I1__(_I1_): pass
@@ -134,7 +157,8 @@
 class _I2(_I1__):
     def f21(): pass
     def f22(): pass
-    def f23(): pass
+    f23 = f22
+    
 
 def test_suite():
     return unittest.makeSuite(InterfaceTests)