[Zope3-checkins] CVS: Zope3/src/zope/component/tests - test_factory.py:1.2

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Mar 9 07:40:07 EST 2004


Update of /cvs-repository/Zope3/src/zope/component/tests
In directory cvs.zope.org:/tmp/cvs-serv10679/src/zope/component/tests

Added Files:
	test_factory.py 
Log Message:


Test the new Factory class.



There were also no tests for the other factory-related functions, so I added a
one for each.




=== Zope3/src/zope/component/tests/test_factory.py 1.1 => 1.2 ===
--- /dev/null	Tue Mar  9 07:40:07 2004
+++ Zope3/src/zope/component/tests/test_factory.py	Tue Mar  9 07:40:07 2004
@@ -0,0 +1,86 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Factory-related Tests
+
+$Id$
+"""
+import unittest
+from zope.interface import Interface, implements
+
+from zope.component import createObject, getFactoryInterfaces, getFactoriesFor
+from zope.component.interfaces import IFactory
+from zope.component.utility import utilityService
+from zope.component.factory import Factory
+from placelesssetup import PlacelessSetup
+
+class IKlass(Interface):
+    pass
+
+class Klass(object):
+    implements(IKlass)
+
+    def __init__(self, *args, **kw):
+        self.args = args
+        self.kw = kw
+
+
+class TestFactory(unittest.TestCase):
+
+    def setUp(self):
+        self._factory = Factory(Klass, 'Klass', 'Klassier')
+
+    def testCall(self):
+        kl = self._factory(3, foo=4)
+        self.assert_(isinstance(kl, Klass))
+        self.assertEqual(kl.args, (3, ))
+        self.assertEqual(kl.kw, {'foo': 4})
+
+    def testTitleDescription(self):
+        self.assertEqual(self._factory.title, 'Klass')
+        self.assertEqual(self._factory.description, 'Klassier')
+
+    def testGetInterfaces(self):
+        self.assertEqual(self._factory.getInterfaces(), [IKlass])
+        
+    
+class TestFactoryZAPIFunctions(PlacelessSetup, unittest.TestCase):
+
+    def setUp(self):
+        super(TestFactoryZAPIFunctions, self).setUp()
+        self.factory = Factory(Klass, 'Klass', 'Klassier')
+        utilityService.provideUtility(IFactory, self.factory, 'klass')
+
+    def testCreateObject(self):
+        kl = createObject(None, 'klass', 3, foo=4)
+        self.assert_(isinstance(kl, Klass))
+        self.assertEqual(kl.args, (3, ))
+        self.assertEqual(kl.kw, {'foo': 4})
+
+    def testGetFactoryInterfaces(self):
+        self.assertEqual(getFactoryInterfaces(None, 'klass'), [IKlass])
+
+    def testGetFactoriesFor(self):
+        self.assertEqual(getFactoriesFor(None, IKlass),
+                         [('klass', self.factory)])
+        
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestFactory),
+        unittest.makeSuite(TestFactoryZAPIFunctions)
+        ))
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')
+




More information about the Zope3-Checkins mailing list