[Zope-Checkins] CVS: Zope3/lib/python/Interface/tests - testInterface.py:1.1.4.3 testVerify.py:1.1.2.4
Jim Fulton
jim@zope.com
Tue, 5 Mar 2002 17:48:25 -0500
Update of /cvs-repository/Zope3/lib/python/Interface/tests
In directory cvs.zope.org:/tmp/cvs-serv3617/Interface/tests
Modified Files:
Tag: Zope-3x-branch
testInterface.py testVerify.py
Log Message:
Interface didn't properly implementg IInterface, because I changed
IImplements today. :)
I fixed this:
- Fixed Verify so that it would at least recognize that the
implementation didn't accept enough arguments for a couple of
methods.
- Added unit tests to check the semantics that Verify can't check.
- Fixed the implementation to pass the tests (and the stricter
verification.)
Note that a previous checkin failed to mention that verify no longer
checks parameter names, since we have decided that these are not part
of the contract. It would be sort of nice, in the future to be able to
spell which names *are* part of the contact (i.e. which parameters can
be given as keyword arguments)
=== Zope3/lib/python/Interface/tests/testInterface.py 1.1.4.2 => 1.1.4.3 ===
from Interface.Implements import instancesOfObjectImplements
from Interface.Implements import objectImplements
+from Interface import Interface
class InterfaceTests(unittest.TestCase):
@@ -78,7 +79,37 @@
from Interface.Verify import verifyClass
assert verifyClass(FooInterface, Foo)
assert Interface.isImplementedBy(I1)
+
+ def test_names(self):
+ names = list(_I2.names()); names.sort()
+ self.assertEqual(names, ['f21', 'f22', 'f23'])
+ names = list(_I2.names(1)); names.sort()
+ self.assertEqual(names, ['f11', 'f12', 'f21', 'f22', 'f23'])
+
+ def test_namesAndDescriptions(self):
+ names = [nd[0] for nd in _I2.namesAndDescriptions()]; names.sort()
+ self.assertEqual(names, ['f21', 'f22', 'f23'])
+ names = [nd[0] for nd in _I2.namesAndDescriptions(1)]; names.sort()
+ self.assertEqual(names, ['f11', 'f12', 'f21', 'f22', 'f23'])
+
+ for name, d in _I2.namesAndDescriptions(1):
+ self.assertEqual(name, d.__name__)
+
+ def test_getDescriptionFor(self):
+ self.assertEqual(_I2.getDescriptionFor('f11').__name__, 'f11')
+ self.assertEqual(_I2.getDescriptionFor('f22').__name__, 'f22')
+ self.assertEqual(_I2.getDescriptionFor('f33', self), self)
+ self.assertRaises(KeyError, _I2.getDescriptionFor, 'f33')
+
+class _I1(Interface):
+ def f11(): pass
+ def f12(): pass
+
+class _I2(_I1):
+ def f21(): pass
+ def f22(): pass
+ def f23(): pass
def test_suite():
return unittest.makeSuite(InterfaceTests)
=== Zope3/lib/python/Interface/tests/testVerify.py 1.1.2.3 => 1.1.2.4 ===
C.f=lambda self, **kw: None
+ self.assertRaises(BrokenMethodImplementation, verifyClass, I, C)
+
+ C.f=lambda self, a, *args: None
+
+ verifyClass(I, C)
+
+ C.f=lambda self, a, *args, **kw: None
+
+ verifyClass(I, C)
+
+ C.f=lambda self, *args: None
+
verifyClass(I, C)
def testExtraArgs(self):