[Zope3-checkins] CVS: Zope3/src/zope/interface/tests - test_declarations.py:1.7
Jim Fulton
jim@zope.com
Wed, 4 Jun 2003 18:25:31 -0400
Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv26183/src/zope/interface/tests
Modified Files:
test_declarations.py
Log Message:
Made interface specifications picklable. This is necessary to deal
with interface assertions on instances and will be needed for
interface assertions on persistent classes.
=== Zope3/src/zope/interface/tests/test_declarations.py 1.6 => 1.7 ===
--- Zope3/src/zope/interface/tests/test_declarations.py:1.6 Mon Jun 2 10:46:16 2003
+++ Zope3/src/zope/interface/tests/test_declarations.py Wed Jun 4 18:25:00 2003
@@ -190,6 +190,100 @@
"""
+def test_computeSignature():
+ """Compute a specification signature
+
+ For example::
+
+ >>> from zope.interface import Interface
+ >>> class I1(Interface): pass
+ ...
+ >>> class I2(I1): pass
+ ...
+ >>> spec = InterfaceSpecification(I2)
+ >>> int(spec.__signature__ == "%s\\t%s\\t%s" % (
+ ... I2.__identifier__, I1.__identifier__,
+ ... Interface.__identifier__))
+ 1
+
+ """
+
+def test_cant_pickle_plain_specs():
+ """
+ >>> from pickle import dumps
+ >>> dumps(InterfaceSpecification())
+ Traceback (most recent call last):
+ ...
+ TypeError: can't pickle InterfaceSpecification objects
+ >>> dumps(InterfaceSpecification(), 2)
+ Traceback (most recent call last):
+ ...
+ TypeError: can't pickle InterfaceSpecification objects
+
+ """
+
+def test_pickle_provides_specs():
+ """
+ >>> from pickle import dumps, loads
+ >>> a = A()
+ >>> int(I2.isImplementedBy(a))
+ 0
+ >>> directlyProvides(a, I2)
+ >>> int(I2.isImplementedBy(a))
+ 1
+ >>> a2 = loads(dumps(a))
+ >>> int(I2.isImplementedBy(a2))
+ 1
+
+ """
+
+def test_pickle_implements_specs():
+ """
+ >>> from pickle import dumps, loads
+ >>> class A:
+ ... implements(I1)
+ >>> class B(A):
+ ... implements(I2)
+ >>> names = [i.__name__ for i in implementedBy(B)]
+ >>> names
+ ['I2', 'I1']
+ >>> old = B.__dict__['__implements__']
+ >>> new = loads(dumps(old))
+ >>> names = [i.__name__ for i in new]
+ >>> names
+ ['I2']
+ >>> classImplements(A, I3)
+ >>> B.__implements__ = new
+ >>> names = [i.__name__ for i in implementedBy(B)]
+ >>> names
+ ['I2', 'I1', 'I3']
+
+ """
+
+def test_pickle_only_specs():
+ """
+ >>> from pickle import dumps, loads
+ >>> class A:
+ ... implements(I1)
+ >>> class B(A):
+ ... implementsOnly(I2)
+ >>> names = [i.__name__ for i in implementedBy(B)]
+ >>> names
+ ['I2']
+ >>> old = B.__dict__['__implements__']
+ >>> new = loads(dumps(old))
+ >>> names = [i.__name__ for i in new]
+ >>> names
+ ['I2']
+ >>> classImplements(A, I3)
+ >>> B.__implements__ = new
+ >>> names = [i.__name__ for i in implementedBy(B)]
+ >>> names
+ ['I2']
+
+ """
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))