[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/ Added a helper function that sets up next services for testing.

Daniel Nouri dpunktnpunkt at web.de
Sat Oct 9 10:18:08 EDT 2004


Log message for revision 27836:
  Added a helper function that sets up next services for testing.
  


Changed:
  U   Zope3/trunk/src/zope/app/component/localservice.py
  U   Zope3/trunk/src/zope/app/component/tests/test_localservice.py


-=-
Modified: Zope3/trunk/src/zope/app/component/localservice.py
===================================================================
--- Zope3/trunk/src/zope/app/component/localservice.py	2004-10-09 14:16:47 UTC (rev 27835)
+++ Zope3/trunk/src/zope/app/component/localservice.py	2004-10-09 14:18:08 UTC (rev 27836)
@@ -150,3 +150,34 @@
 clearSite = setSite
 
 addCleanUp(clearSite)
+
+
+class FakeServices:
+    implements(ISiteManager)
+    
+    def __init__(self):
+        self.data = {}
+    
+    def getService(self, name):
+        return self.data[name]
+        
+
+def testingNextService(service, nextservice, servicename):
+    """A helper function that sets up next services for testing
+
+    >>> class MyService:
+    ...     __parent__ = None
+
+    >>> myfakeservice = object()
+    >>> service = MyService()
+    >>> testingNextService(service, myfakeservice, 'foo')
+    >>> getNextService(service, 'foo') is myfakeservice
+    True
+    """
+
+    if service.__parent__ is None:
+        service.__parent__ = FakeServices()
+        service.__parent__.next = FakeServices()
+
+    service.__parent__.next.data[servicename] = nextservice
+        

Modified: Zope3/trunk/src/zope/app/component/tests/test_localservice.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_localservice.py	2004-10-09 14:16:47 UTC (rev 27835)
+++ Zope3/trunk/src/zope/app/component/tests/test_localservice.py	2004-10-09 14:18:08 UTC (rev 27836)
@@ -26,6 +26,8 @@
 from zope.component.service import serviceManager
 from zope.interface import implements, directlyProvides, directlyProvidedBy
 from zope.interface.verify import verifyObject
+from zope.testing import doctest
+
 from zope.app.tests.setup import placelessSetUp, placelessTearDown
 from zope.app.tests import ztapi
 from zope.app.component.hooks import setSite, getSite
@@ -264,7 +266,9 @@
 
 
 def test_suite():
-    return unittest.makeSuite(Test)
+    suite = unittest.makeSuite(Test)
+    suite.addTest(doctest.DocTestSuite('zope.app.component.localservice'))
+    return suite
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')



More information about the Zope3-Checkins mailing list