[Zodb-checkins] CVS: Zope3/src/zope/interface/tests -
test_declarations.py:1.9.6.2 test_interface.py:1.7.22.2
Jim Fulton
cvs-admin at zope.org
Thu Nov 6 07:35:11 EST 2003
Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv30369/src/zope/interface/tests
Modified Files:
Tag: adaptergeddon-branch
test_declarations.py test_interface.py
Log Message:
Created some new C optimizations for interfaces.
Small optimization in specification lookup.
=== Zope3/src/zope/interface/tests/test_declarations.py 1.9.6.1 => 1.9.6.2 ===
--- Zope3/src/zope/interface/tests/test_declarations.py:1.9.6.1 Sat Oct 11 10:19:04 2003
+++ Zope3/src/zope/interface/tests/test_declarations.py Thu Nov 6 07:35:10 2003
@@ -198,6 +198,88 @@
"""
+def test_that_we_dont_inherit_class_provides():
+ """
+ >>> class X:
+ ... classProvides(I1)
+ >>> class Y(X):
+ ... pass
+ >>> [i.__name__ for i in X.__provides__]
+ ['I1']
+ >>> Y.__provides__
+ Traceback (most recent call last):
+ ...
+ AttributeError: __provides__
+
+ """
+
+def test_that_we_dont_inherit_provides_optimizations():
+ """
+
+ When we make a declaration for a class, we install a __provides__
+ descriptors that provides a default for instances that don't have
+ instance-specific declarations:
+
+ >>> class A:
+ ... implements(I1)
+
+ >>> class B:
+ ... implements(I2)
+
+ >>> [i.__name__ for i in A().__provides__]
+ ['I1']
+ >>> [i.__name__ for i in B().__provides__]
+ ['I2']
+
+ But it's important that we don't use this for subclasses without
+ declarations. This would cause incorrect results:
+
+ >>> class X(A, B):
+ ... pass
+
+ >>> X().__provides__
+ Traceback (most recent call last):
+ ...
+ AttributeError: __provides__
+
+ However, if we "induce" a declaration, by calling implementedBy
+ (even indirectly through providedBy):
+
+ >>> [i.__name__ for i in providedBy(X())]
+ ['I1', 'I2']
+
+
+ then the optimization will work:
+
+ >>> [i.__name__ for i in X().__provides__]
+ ['I1', 'I2']
+
+ """
+
+def test_classProvides_before_implements():
+ """Special descriptor for class __provides__
+
+ The descriptor caches the implementedBy info, so that
+ we can get declarations for objects without instance-specific
+ interfaces a bit quicker.
+
+ For example::
+
+ >>> from zope.interface import Interface
+ >>> class IFooFactory(Interface):
+ ... pass
+ >>> class IFoo(Interface):
+ ... pass
+ >>> class C:
+ ... classProvides(IFooFactory)
+ ... implements(IFoo)
+ >>> [i.getName() for i in C.__provides__]
+ ['IFooFactory']
+
+ >>> [i.getName() for i in C().__provides__]
+ ['IFoo']
+ """
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
=== Zope3/src/zope/interface/tests/test_interface.py 1.7.22.1 => 1.7.22.2 ===
--- Zope3/src/zope/interface/tests/test_interface.py:1.7.22.1 Sat Oct 11 10:51:19 2003
+++ Zope3/src/zope/interface/tests/test_interface.py Thu Nov 6 07:35:10 2003
@@ -30,56 +30,54 @@
pass
def testClassImplements(self):
- assert IC.isImplementedByInstancesOf(C)
+ self.assert_(IC.isImplementedByInstancesOf(C))
- assert I1.isImplementedByInstancesOf(A)
- assert I1.isImplementedByInstancesOf(B)
- assert not I1.isImplementedByInstancesOf(C)
- assert I1.isImplementedByInstancesOf(D)
- assert I1.isImplementedByInstancesOf(E)
-
- assert not I2.isImplementedByInstancesOf(A)
- assert I2.isImplementedByInstancesOf(B)
- assert not I2.isImplementedByInstancesOf(C)
+ self.assert_(I1.isImplementedByInstancesOf(A))
+ self.assert_(I1.isImplementedByInstancesOf(B))
+ self.assert_(not I1.isImplementedByInstancesOf(C))
+ self.assert_(I1.isImplementedByInstancesOf(D))
+ self.assert_(I1.isImplementedByInstancesOf(E))
+
+ self.assert_(not I2.isImplementedByInstancesOf(A))
+ self.assert_(I2.isImplementedByInstancesOf(B))
+ self.assert_(not I2.isImplementedByInstancesOf(C))
# No longer after interfacegeddon
- # assert not I2.isImplementedByInstancesOf(D)
+ # self.assert_(not I2.isImplementedByInstancesOf(D))
- assert not I2.isImplementedByInstancesOf(E)
+ self.assert_(not I2.isImplementedByInstancesOf(E))
def testUtil(self):
- f = implementedBy
- assert IC in f(C)
- assert I1 in f(A)
- assert not I1 in f(C)
- assert I2 in f(B)
- assert not I2 in f(C)
-
- f = providedBy
- assert IC in f(C())
- assert I1 in f(A())
- assert not I1 in f(C())
- assert I2 in f(B())
- assert not I2 in f(C())
+ self.assert_(IC in implementedBy(C))
+ self.assert_(I1 in implementedBy(A))
+ self.assert_(not I1 in implementedBy(C))
+ self.assert_(I2 in implementedBy(B))
+ self.assert_(not I2 in implementedBy(C))
+
+ self.assert_(IC in providedBy(C()))
+ self.assert_(I1 in providedBy(A()))
+ self.assert_(not I1 in providedBy(C()))
+ self.assert_(I2 in providedBy(B()))
+ self.assert_(not I2 in providedBy(C()))
def testObjectImplements(self):
- assert IC.isImplementedBy(C())
+ self.assert_(IC.isImplementedBy(C()))
- assert I1.isImplementedBy(A())
- assert I1.isImplementedBy(B())
- assert not I1.isImplementedBy(C())
- assert I1.isImplementedBy(D())
- assert I1.isImplementedBy(E())
-
- assert not I2.isImplementedBy(A())
- assert I2.isImplementedBy(B())
- assert not I2.isImplementedBy(C())
+ self.assert_(I1.isImplementedBy(A()))
+ self.assert_(I1.isImplementedBy(B()))
+ self.assert_(not I1.isImplementedBy(C()))
+ self.assert_(I1.isImplementedBy(D()))
+ self.assert_(I1.isImplementedBy(E()))
+
+ self.assert_(not I2.isImplementedBy(A()))
+ self.assert_(I2.isImplementedBy(B()))
+ self.assert_(not I2.isImplementedBy(C()))
# Not after interface geddon
- # assert not I2.isImplementedBy(D())
+ # self.assert_(not I2.isImplementedBy(D()))
- assert not I2.isImplementedBy(E())
+ self.assert_(not I2.isImplementedBy(E()))
def testDeferredClass(self):
a = A()
@@ -87,18 +85,18 @@
def testInterfaceExtendsInterface(self):
- assert BazInterface.extends(BobInterface)
- assert BazInterface.extends(BarInterface)
- assert BazInterface.extends(FunInterface)
- assert not BobInterface.extends(FunInterface)
- assert not BobInterface.extends(BarInterface)
- assert BarInterface.extends(FunInterface)
- assert not BarInterface.extends(BazInterface)
+ self.assert_(BazInterface.extends(BobInterface))
+ self.assert_(BazInterface.extends(BarInterface))
+ self.assert_(BazInterface.extends(FunInterface))
+ self.assert_(not BobInterface.extends(FunInterface))
+ self.assert_(not BobInterface.extends(BarInterface))
+ self.assert_(BarInterface.extends(FunInterface))
+ self.assert_(not BarInterface.extends(BazInterface))
def testVerifyImplementation(self):
from zope.interface.verify import verifyClass
- assert verifyClass(FooInterface, Foo)
- assert Interface.isImplementedBy(I1)
+ self.assert_(verifyClass(FooInterface, Foo))
+ self.assert_(Interface.isImplementedBy(I1))
def test_names(self):
names = list(_I2.names()); names.sort()
More information about the Zodb-checkins
mailing list