[Zope3-checkins] CVS: Zope3/src/zope/interface/tests -
test_surrogate.py:1.1.2.2
Jim Fulton
cvs-admin at zope.org
Sun Nov 9 11:09:04 EST 2003
Update of /cvs-repository/Zope3/src/zope/interface/tests
In directory cvs.zope.org:/tmp/cvs-serv15349/src/zope/interface/tests
Modified Files:
Tag: adaptergeddon-branch
test_surrogate.py
Log Message:
Created a global presentation service that replaces the
global view, resource, and skin services.
Now look up presentation components by adapting from a request type,
rather than adapting to a presentation type.
=== Zope3/src/zope/interface/tests/test_surrogate.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/interface/tests/test_surrogate.py:1.1.2.1 Fri Oct 10 07:16:38 2003
+++ Zope3/src/zope/interface/tests/test_surrogate.py Sun Nov 9 11:08:34 2003
@@ -17,14 +17,118 @@
"""
import unittest
from zope.testing.doctestunit import DocTestSuite
+from zope.interface.surrogate import SurrogateRegistry
-def test_xxx():
+def test_multi_adapter_w_default():
"""
+ >>> import zope.interface
+ >>> class IF0(zope.interface.Interface):
+ ... pass
+ >>> class IF1(IF0):
+ ... pass
+
+
+ >>> class IR0(zope.interface.Interface):
+ ... pass
+ >>> class IR1(IR0):
+ ... pass
+
+ >>> class F1:
+ ... zope.interface.implements(IF1)
+ >>> c = F1()
+
+ >>> class R1:
+ ... zope.interface.implements(IR1)
+ >>> r = R1()
+
+ >>> registry = SurrogateRegistry()
+
+ >>> class IB0(zope.interface.Interface):
+ ... pass
+ >>> class IB1(IB0):
+ ... pass
+
+ >>> class f1:
+ ... def __init__(self, x, y):
+ ... self.x, self.y = x, y
+
+ >>> registry.provideAdapter(None, IB1, [f1], name='bob', with=[IR0])
+
+ >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+ >>> a.__class__ is f1
+ True
+ >>> a.x is c
+ True
+ >>> a.y is r
+ True
+
+ >>> registry.queryMultiAdapter((c, r), IB0, 'bruce')
+
+ >>> class f2(f1):
+ ... pass
+
+ >>> registry.provideAdapter(None, IB1, [f2], name='bob', with=[IR1])
+ >>> a = registry.queryMultiAdapter((c, r), IB0, 'bob')
+ >>> a.__class__ is f2
+ True
+ >>> a.x is c
+ True
+ >>> a.y is r
+ True
+
"""
+def test_named_adapter_with_default():
+ """Query a named simple adapter
+
+ >>> import zope.interface
+ >>> class F0(zope.interface.Interface):
+ ... pass
+ >>> class F1(F0):
+ ... pass
+
+ >>> class C:
+ ... zope.interface.implements(F1)
+ >>> c = C()
+
+ >>> registry = SurrogateRegistry()
+
+ If we ask for a named adapter, we won't get a result unless there
+ is a named adapter, even if the object implements the interface:
+
+ >>> registry.queryNamedAdapter(c, F0, 'bob')
+
+ >>> class B0(zope.interface.Interface):
+ ... pass
+ >>> class B1(B0):
+ ... pass
+
+
+ >>> def f1(ob):
+ ... return 1
+
+ >>> registry.provideAdapter(None, B1, [f1], name='bob')
+ >>> registry.queryNamedAdapter(c, B0, 'bob')
+ 1
+ >>> registry.queryNamedAdapter(c, B0, 'bruce')
+
+
+ >>> def f3(ob):
+ ... return 3
+
+ >>> registry.provideAdapter(None, B0, [f3], name='bob')
+ >>> registry.queryNamedAdapter(c, B0, 'bob')
+ 3
+
+
+ """
+
+
+
def test_suite():
return unittest.TestSuite((
DocTestSuite('zope.interface.surrogate'),
+ DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
More information about the Zope3-Checkins
mailing list