[Zope3-checkins] SVN: Zope3/branches/srichter-blow-services/src/zope/component/ All tests pass now and the factory tests are converted to doctests,

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Dec 16 15:54:29 EST 2004


Log message for revision 28636:
  All tests pass now and the factory tests are converted to doctests, 
  though I still have to document the tests. I also have to raise many more 
  deprecation warnings all over the place.
  
  

Changed:
  U   Zope3/branches/srichter-blow-services/src/zope/component/__init__.py
  U   Zope3/branches/srichter-blow-services/src/zope/component/bbb/tests/__init__.py
  U   Zope3/branches/srichter-blow-services/src/zope/component/factory.txt
  U   Zope3/branches/srichter-blow-services/src/zope/component/testing.py
  U   Zope3/branches/srichter-blow-services/src/zope/component/tests.py

-=-
Modified: Zope3/branches/srichter-blow-services/src/zope/component/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/__init__.py	2004-12-16 18:06:40 UTC (rev 28635)
+++ Zope3/branches/srichter-blow-services/src/zope/component/__init__.py	2004-12-16 20:54:28 UTC (rev 28636)
@@ -39,6 +39,14 @@
 from zope.component.bbb import contextdependent
 sys.modules['zope.component.contextdependent'] = contextdependent
 
+from zope.component.bbb.tests import placelesssetup
+sys.modules['zope.component.tests.placelesssetup'] = placelesssetup
+from zope.component.bbb.tests import request
+sys.modules['zope.component.tests.request'] = request
+from zope.component.bbb.tests import components
+sys.modules['zope.component.tests.components'] = components
+
+
 service.__warn__ = False
 service.serviceManager = service.GlobalServiceManager(
     'serviceManager', __name__, globalSiteManager)

Modified: Zope3/branches/srichter-blow-services/src/zope/component/bbb/tests/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/bbb/tests/__init__.py	2004-12-16 18:06:40 UTC (rev 28635)
+++ Zope3/branches/srichter-blow-services/src/zope/component/bbb/tests/__init__.py	2004-12-16 20:54:28 UTC (rev 28636)
@@ -1 +1,2 @@
 # Make directory a package.
+

Modified: Zope3/branches/srichter-blow-services/src/zope/component/factory.txt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/factory.txt	2004-12-16 18:06:40 UTC (rev 28635)
+++ Zope3/branches/srichter-blow-services/src/zope/component/factory.txt	2004-12-16 20:54:28 UTC (rev 28636)
@@ -1,129 +1,136 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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
+=========
+Factories
+=========
 
-$Id$
-"""
-import unittest
-from zope.interface import Interface, implements
 
-from zope import component as capi
-from zope.component.interfaces import IFactory
-from zope.component.factory import Factory
-from zope.component.tests.placelesssetup import setUp, tearDown
-from zope.testing import doctest
+The Factory Class
+-----------------
 
-class IFunction(Interface):
-    pass
+  >>> from zope.interface import Interface
+  >>> class IFunction(Interface):
+  ...     pass
 
-class IKlass(Interface):
-    pass
+  >>> class IKlass(Interface):
+  ...     pass
 
-class Klass(object):
-    implements(IKlass)
+  >>> from zope.interface import implements
+  >>> class Klass(object):
+  ...     implements(IKlass)
+  ... 
+  ...     def __init__(self, *args, **kw):
+  ...         self.args = args
+  ...         self.kw = kw
 
-    def __init__(self, *args, **kw):
-        self.args = args
-        self.kw = kw
+  >>> from zope.component.factory import Factory
+  >>> factory = Factory(Klass, 'Klass', 'Klassier')
+  >>> factory2 = Factory(lambda x: x, 'Func', 'Function')
+  >>> factory3 = Factory(lambda x: x, 'Func', 'Function', (IFunction,))
 
-factory = Factory(Klass, 'Klass', 'Klassier')
-factory2 = Factory(lambda x: x, 'Func', 'Function')
-factory3 = Factory(lambda x: x, 'Func', 'Function', (IFunction,))
+Calling a Factory
++++++++++++++++++
 
-def testFactoryCall():
-    """Here we test whether the factory correctly creates the objects and
-    including the correct handling of constructor elements.
+Here we test whether the factory correctly creates the objects and
+including the correct handling of constructor elements.
 
-    First we create a factory that creates instanace of the `Klass` class:
+First we create a factory that creates instanace of the `Klass` class:
 
-      >>> factory = Factory(Klass, 'Klass', 'Klassier')
+  >>> factory = Factory(Klass, 'Klass', 'Klassier')
 
-    Now we use the factory to create the instance
-    
-      >>> kl = factory(1, 2, foo=3, bar=4)
+Now we use the factory to create the instance
 
-    and make sure that the correct class was used to create the object:
-    
-      >>> kl.__class__
-      <>
+  >>> kl = factory(1, 2, foo=3, bar=4)
 
-    Since we passed in a couple positional and keyword arguments
-      
-      >>> kl.args
-      (1, 2)
-      >>> kl.kw
-      {'foo': 3, 'bar': 4}
-      
-      >>> factory2(3)
-      3
-      >>> factory3(3)
-      3
-    """
+and make sure that the correct class was used to create the object:
 
-def testTitleDescription(self):
-    self.assertEqual(self._factory.title, 'Klass')
-    self.assertEqual(self._factory.description, 'Klassier')
-    self.assertEqual(self._factory2.title, 'Func')
-    self.assertEqual(self._factory2.description, 'Function')
-    self.assertEqual(self._factory3.title, 'Func')
-    self.assertEqual(self._factory3.description, 'Function')
+  >>> kl.__class__
+  <class 'Klass'>
 
-def testGetInterfaces(self):
-    implemented = self._factory.getInterfaces()
-    self.assert_(implemented.isOrExtends(IKlass))
-    self.assertEqual(list(implemented), [IKlass])
-    self.assertEqual(implemented.__name__,
-                     'zope.component.tests.test_factory.Klass')
+Since we passed in a couple positional and keyword arguments
+  
+  >>> kl.args
+  (1, 2)
+  >>> kl.kw
+  {'foo': 3, 'bar': 4}
+  
+  >>> factory2(3)
+  3
+  >>> factory3(3)
+  3
 
-    implemented2 = self._factory2.getInterfaces()
-    self.assertEqual(list(implemented2), [])
-    self.assertEqual(implemented2.__name__, '<lambda>')
 
-    implemented3 = self._factory3.getInterfaces()
-    self.assertEqual(list(implemented3), [IFunction])
-    self.assertEqual(implemented3.__name__, '<lambda>')
+Title and Description
++++++++++++++++++++++
 
+  >>> factory.title
+  'Klass'
+  >>> factory.description
+  'Klassier'
+  >>> factory2.title
+  'Func'
+  >>> factory2.description
+  'Function'
+  >>> factory3.title
+  'Func'
+  >>> factory3.description
+  'Function'
 
-class TestFactoryZAPIFunctions(PlacelessSetup, unittest.TestCase):
 
-    def setUp(self):
-        super(TestFactoryZAPIFunctions, self).setUp()
-        self.factory = Factory(Klass, 'Klass', 'Klassier')
-        gsm = capi.getGlobalSiteManager() 
-        gsm.registerUtility(IFactory, self.factory, 'klass')
+Provided Interfaces
++++++++++++++++++++
 
-    def testCreateObject(self):
-        kl = capi.createObject(None, 'klass', 3, foo=4)
-        self.assert_(isinstance(kl, Klass))
-        self.assertEqual(kl.args, (3, ))
-        self.assertEqual(kl.kw, {'foo': 4})
+  >>> implemented = factory.getInterfaces()
+  >>> implemented.isOrExtends(IKlass)
+  True
+  >>> list(implemented)
+  [<InterfaceClass __builtin__.IKlass>]
+  >>> implemented.__name__
+  '__builtin__.Klass'
+  
+  >>> implemented2 = factory2.getInterfaces()
+  >>> list(implemented2)
+  []
+  >>> implemented2.__name__
+  '<lambda>'
+  
+  >>> implemented3 = factory3.getInterfaces()
+  >>> list(implemented3)
+  [<InterfaceClass __builtin__.IFunction>]
+  >>> implemented3.__name__
+  '<lambda>'
 
-    def testGetFactoryInterfaces(self):
-        implemented = capi.getFactoryInterfaces('klass')
-        self.assert_(implemented.isOrExtends(IKlass))
-        self.assertEqual([iface for iface in implemented], [IKlass])
 
-    def testGetFactoriesFor(self):
-        self.assertEqual(list(capi.getFactoriesFor(IKlass)),
-                         [('klass', self.factory)])
+The Componant Architecture Factory API
+--------------------------------------
 
+  >>> from zope import component as capi
+  >>> factory = Factory(Klass, 'Klass', 'Klassier')
+  >>> gsm = capi.getGlobalSiteManager() 
 
-def test_suite():
-    return unittest.TestSuite((
-        doctest.DocTestSuite(),
-        ))
+  >>> from zope.component.interfaces import IFactory
+  >>> gsm.registerUtility(IFactory, factory, 'klass')
 
-if __name__=='__main__':
-    unittest.main(defaultTest='test_suite')
+Creating an Object
+++++++++++++++++++
 
+  >>> kl = capi.createObject(None, 'klass', 1, 2, foo=3, bar=4)
+  >>> isinstance(kl, Klass)
+  True
+  >>> kl.args
+  (1, 2)
+  >>> kl.kw
+  {'foo': 3, 'bar': 4}
+
+Accessing Provided Interfaces
++++++++++++++++++++++++++++++
+
+  >>> implemented = capi.getFactoryInterfaces('klass')
+  >>> implemented.isOrExtends(IKlass)
+  True
+  >>> [iface for iface in implemented]
+  [<InterfaceClass __builtin__.IKlass>]
+
+List of All Factories
++++++++++++++++++++++
+
+  >>> [(name, fac.__class__) for name, fac in capi.getFactoriesFor(IKlass)]
+  [(u'klass', <class 'zope.component.factory.Factory'>)]

Modified: Zope3/branches/srichter-blow-services/src/zope/component/testing.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/testing.py	2004-12-16 18:06:40 UTC (rev 28635)
+++ Zope3/branches/srichter-blow-services/src/zope/component/testing.py	2004-12-16 20:54:28 UTC (rev 28636)
@@ -15,30 +15,20 @@
 
 $Id$
 """
-from zope.testing.cleanup import CleanUp
-from zope.component import getGlobalServices
-from zope.component.servicenames import Adapters, Utilities
+from zope.testing import cleanup
 
 # A mix-in class inheriting from CleanUp that also connects the CA services
-class PlacelessSetup(CleanUp):
+class PlacelessSetup(cleanup.CleanUp):
 
     def setUp(self):
-        CleanUp.setUp(self)
-        sm = getGlobalServices()
-        defineService = sm.defineService
-        provideService = sm.provideService
+        super(PlacelessSetup, self).setUp()
 
-        # utility service
-        from zope.component.interfaces import IUtilityService
-        defineService(Utilities, IUtilityService)
-        from zope.component.utility import GlobalUtilityService
-        provideService(Utilities, GlobalUtilityService())
+    def tearDown(self):
+        super(PlacelessSetup, self).tearDown()
 
-        # adapter service
-        from zope.component.interfaces import IAdapterService
-        defineService(Adapters, IAdapterService)
-        from zope.component.adapter import GlobalAdapterService
-        provideService(Adapters, GlobalAdapterService())
 
-    def tearDown(self):
-        CleanUp.tearDown(self)
+def setUp(test):
+    cleanup.setUp()
+
+def tearDown(test):
+    cleanup.tearDown()

Modified: Zope3/branches/srichter-blow-services/src/zope/component/tests.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/component/tests.py	2004-12-16 18:06:40 UTC (rev 28635)
+++ Zope3/branches/srichter-blow-services/src/zope/component/tests.py	2004-12-16 20:54:28 UTC (rev 28636)
@@ -25,9 +25,8 @@
 from zope.component.interfaces import ComponentLookupError
 from zope.component.interfaces import IComponentArchitecture
 from zope.component.interfaces import ISiteManager
-from zope.component.tests.placelesssetup import setUp, tearDown
+from zope.component.testing import setUp, tearDown
 
-
 class I1(Interface):
     pass
 class I2(Interface):
@@ -215,7 +214,7 @@
       Traceback (most recent call last):
       ...
       ComponentLookupError: (<Component implementing 'I1'>,
-                             <InterfaceClass zope.component.tests.test_api.I4>)
+                             <InterfaceClass zope.component.tests.I4>)
 
     ...otherwise, you get the default:
 
@@ -244,7 +243,7 @@
       Traceback (most recent call last):
       ...
       ComponentLookupError: (<instance Ob>,
-                             <InterfaceClass zope.component.tests.test_api.I2>)
+                             <InterfaceClass zope.component.tests.I2>)
 
     ...otherwise, you get the default
 
@@ -290,7 +289,7 @@
       Traceback (most recent call last):
       ...
       TypeError: ('Could not adapt', <instance Ob2>,
-                  <InterfaceClass zope.component.tests.test_api.I1>)
+                  <InterfaceClass zope.component.tests.I1>)
       
     ...unless we specify an alternative adapter:
 
@@ -315,7 +314,7 @@
       Traceback (most recent call last):
       ...
       ComponentLookupError: 
-      (<instance Ob>, <InterfaceClass zope.component.tests.test_api.I2>)
+      (<instance Ob>, <InterfaceClass zope.component.tests.I2>)
 
     ...otherwise, you get the default
 
@@ -353,7 +352,7 @@
       ...
       ComponentLookupError:
       ((<instance Ob>, <instance Ob2>),
-       <InterfaceClass zope.component.tests.test_api.I3>)
+       <InterfaceClass zope.component.tests.I3>)
 
     ...otherwise, you get the default
 
@@ -442,7 +441,7 @@
       Traceback (most recent call last):
       ...
       ComponentLookupError: \
-      (<InterfaceClass zope.component.tests.test_api.I1>, '')
+      (<InterfaceClass zope.component.tests.I1>, '')
 
     ...otherwise, you get the default
 
@@ -474,7 +473,7 @@
       Traceback (most recent call last):
       ...
       ComponentLookupError:
-      (<InterfaceClass zope.component.tests.test_api.I1>, 'foo')
+      (<InterfaceClass zope.component.tests.I1>, 'foo')
 
 
     ...otherwise, you get the default
@@ -539,7 +538,7 @@
       ...
       TypeError: ('Could not adapt',
                   <instance Ob>,
-                  <InterfaceClass zope.component.tests.test_api.I2>)
+                  <InterfaceClass zope.component.tests.I2>)
 
 
       >>> I2(ob, 42)
@@ -550,9 +549,9 @@
     return unittest.TestSuite((
         doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
         doctest.DocTestSuite('zope.component.site'),
-        doctest.DocFileSuite('../README.txt',
+        doctest.DocFileSuite('README.txt',
                              setUp=setUp, tearDown=tearDown),
-        doctest.DocFileSuite('../factory.txt',
+        doctest.DocFileSuite('factory.txt',
                              setUp=setUp, tearDown=tearDown),
         ))
 



More information about the Zope3-Checkins mailing list