[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture/tests - testDirectives.py:1.1.2.5
Jim Fulton
jim@zope.com
Tue, 4 Jun 2002 13:23:26 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture/tests
In directory cvs.zope.org:/tmp/cvs-serv25226/lib/python/Zope/App/ComponentArchitecture/tests
Modified Files:
Tag: Zope3InWonderland-branch
testDirectives.py
Log Message:
Added factory attribute to utility and service directives so that you
can specify a factory rather than an instance. This makes class source
files a little cleaner because they don't need to create an instance.
This is only useful when the instance can be created by calling the
factory without arguments.
=== Zope3/lib/python/Zope/App/ComponentArchitecture/tests/testDirectives.py 1.1.2.4 => 1.1.2.5 ===
self.assertEqual(getUtility(None, IApp), comp)
+ def testUtilityFactory(self):
+ from Zope.ComponentArchitecture import getUtility, queryUtility
+
+ # Full import is critical!
+ from Zope.ComponentArchitecture.tests.TestComponents \
+ import IApp, Comp
+
+ self.assertEqual(queryUtility(None, IV, None), None)
+
+ xmlconfig(StringIO(template % (
+ """
+ <utility
+ factory="Zope.ComponentArchitecture.tests.TestComponents.Comp"
+ provides="Zope.ComponentArchitecture.tests.TestComponents.IApp"
+ />
+ """
+ )))
+
+ self.assertEqual(getUtility(None, IApp).__class__, Comp)
+
def testProtectedUtility(self):
from Zope.ComponentArchitecture import getUtility, queryUtility