[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/tests - testDirectives.py:1.7
Jim Fulton
jim@zope.com
Sun, 15 Dec 2002 15:17:08 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv15449/Zope/App/ComponentArchitecture/tests
Modified Files:
testDirectives.py
Log Message:
Utilities and adapters can now be named.
For example:
x = getAdapter(self, Ifoo, name="spam")
but unnamed adapters and utilities are still the norm and default.
=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testDirectives.py 1.6 => 1.7 ===
--- Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testDirectives.py:1.6 Mon Nov 25 10:23:20 2002
+++ Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testDirectives.py Sun Dec 15 15:16:38 2002
@@ -77,6 +77,33 @@
self.assertEqual(getAdapter(Content(), IApp).__class__, Comp)
+ def testNamedAdapter(self):
+
+ from Zope.ComponentArchitecture import getAdapter, queryAdapter
+
+ # Full import is critical!
+ from Zope.ComponentArchitecture.tests.TestComponents \
+ import Content, IApp, Comp
+
+ self.testAdapter()
+ self.assertEqual(getAdapter(Content(), IApp).__class__, Comp)
+ self.assertEqual(queryAdapter(Content(), IV, None, name='test'),
+ None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <adapter
+ factory="Zope.ComponentArchitecture.tests.TestComponents.Comp"
+ provides="Zope.ComponentArchitecture.tests.TestComponents.IApp"
+ for="Zope.ComponentArchitecture.tests.TestComponents.IContent"
+ name="test"
+ />
+ """
+ )))
+
+ self.assertEqual(getAdapter(Content(), IApp, name="test").__class__,
+ Comp)
+
def testProtectedAdapter(self):
from Zope.ComponentArchitecture import getAdapter, queryAdapter
@@ -135,6 +162,29 @@
)))
self.assertEqual(getUtility(None, IApp), comp)
+
+ def testNamedUtility(self):
+ from Zope.ComponentArchitecture import getUtility, queryUtility
+
+ # Full import is critical!
+ from Zope.ComponentArchitecture.tests.TestComponents \
+ import IApp, comp
+
+ self.testUtility()
+
+ self.assertEqual(queryUtility(None, IV, None, name='test'), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <utility
+ component="Zope.ComponentArchitecture.tests.TestComponents.comp"
+ provides="Zope.ComponentArchitecture.tests.TestComponents.IApp"
+ name="test"
+ />
+ """
+ )))
+
+ self.assertEqual(getUtility(None, IApp, "test"), comp)
def testUtilityFactory(self):
from Zope.ComponentArchitecture import getUtility, queryUtility