[Zope-Checkins] CVS: Zope3/lib/python/Interface/tests - testImplements.py:1.1.2.1 testVerify.py:1.1.2.1
Jim Fulton
jim@zope.com
Tue, 20 Nov 2001 13:35:36 -0500
Update of /cvs-repository/Zope3/lib/python/Interface/tests
In directory cvs.zope.org:/tmp/cvs-serv10107/tests
Added Files:
Tag: Zope-3x-branch
testImplements.py testVerify.py
Log Message:
fixed interface verification and added Interface.implements
=== Added File Zope3/lib/python/Interface/tests/testImplements.py ===
from Interface import Interface, implements
from Interface.Exceptions import DoesNotImplement, BrokenImplementation
from Interface.Exceptions import BrokenMethodImplementation
import unittest, sys
class Test(unittest.TestCase):
def testSimple(self):
class I(Interface):
def f(): pass
class C: pass
self.assertRaises(BrokenImplementation, implements, C, I)
C.f=lambda self: None
implements(C, I)
self.assertEqual(C.__implements__, I)
def testAdd(self):
class I(Interface):
def f(): pass
class I2(Interface):
def g(): pass
class C:
__implements__=I2
self.assertRaises(BrokenImplementation, implements, C, I)
C.f=lambda self: None
implements(C, I)
self.assertEqual(C.__implements__, (I2, I))
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/lib/python/Interface/tests/testVerify.py ===
from Interface import Interface
from Interface.verify import verify
from Interface.Exceptions import DoesNotImplement, BrokenImplementation
from Interface.Exceptions import BrokenMethodImplementation
import unittest, sys
class Test(unittest.TestCase):
def testNotImplemented(self):
class C: pass
class I(Interface): pass
self.assertRaises(DoesNotImplement, verify, I, C)
C.__implements__=I
verify(I, C)
def testMissingAttr(self):
class I(Interface):
def f(): pass
class C:
__implements__=I
self.assertRaises(BrokenImplementation, verify, I, C)
C.f=lambda self: None
verify(I, C)
def testWrongArgs(self):
class I(Interface):
def f(a): pass
class C:
def f(self, b): pass
__implements__=I
self.assertRaises(BrokenMethodImplementation, verify, I, C)
C.f=lambda self, a: None
verify(I, C)
C.f=lambda self, **kw: None
verify(I, C)
def testExtraArgs(self):
class I(Interface):
def f(a): pass
class C:
def f(self, a, b): pass
__implements__=I
self.assertRaises(BrokenMethodImplementation, verify, I, C)
C.f=lambda self, a: None
verify(I, C)
C.f=lambda self, a, b=None: None
verify(I, C)
def testNoVar(self):
class I(Interface):
def f(a, *args): pass
class C:
def f(self, a): pass
__implements__=I
self.assertRaises(BrokenMethodImplementation, verify, I, C)
C.f=lambda self, a, *foo: None
verify(I, C)
def testNoKW(self):
class I(Interface):
def f(a, **args): pass
class C:
def f(self, a): pass
__implements__=I
self.assertRaises(BrokenMethodImplementation, verify, I, C)
C.f=lambda self, a, **foo: None
verify(I, C)
def test_suite():
loader=unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())