[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_modulelookup.py:1.2 test_adapter.py:1.20 test_view.py:1.20

Jim Fulton jim@zope.com
Mon, 30 Jun 2003 12:37:15 -0400


Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv20472/src/zope/app/services/tests

Modified Files:
	test_adapter.py test_view.py 
Added Files:
	test_modulelookup.py 
Log Message:
Changed module-global lookup logic to use the module-lookup methods of
registration manager containers.


=== Zope3/src/zope/app/services/tests/test_modulelookup.py 1.1 => 1.2 ===
--- /dev/null	Mon Jun 30 12:37:15 2003
+++ Zope3/src/zope/app/services/tests/test_modulelookup.py	Mon Jun 30 12:37:14 2003
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# Copyright (c) 2003 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.
+#
+##############################################################################
+"""Local module lookup tests
+
+Note that when we get around to implementing module services, those
+tests will go here too.
+
+$Id$
+"""
+
+from zope.testing.doctestunit import DocTestSuite
+from zope.context import Wrapper
+
+from zope.app.services.registration import RegistrationManagerContainer
+from zope.app.interfaces.services.module import IModuleManager
+from zope.interface import implements
+
+
+class MyModuleManager(object):
+    implements(IModuleManager)
+    
+    def __init__(self, module):
+        self.module = module
+
+    def getModule(self):
+        return self.module
+
+class MyFolder(RegistrationManagerContainer, dict):
+    def setObject(self, name, object):
+        self[name] = object
+        return name
+
+
+def test_findMoule():
+    """
+
+    >>> folder = MyFolder()
+    >>> folder['m1.py'] = MyModuleManager(1)
+    >>> folder['m1'] = MyModuleManager(0)
+    >>> folder['m2'] = MyModuleManager(2)
+    >>> next = MyFolder()
+    >>> next['m3'] = MyModuleManager(3)
+    >>> next['z.y.m4'] = MyModuleManager(4)
+    >>> folder = Wrapper(folder, next)
+
+    >>> folder.findModule('m1')
+    1
+    >>> folder.findModule('m2')
+    2
+    >>> folder.findModule('m3')
+    3
+    >>> folder.findModule('z.y.m4')
+    4
+    >>> folder.findModule('m5')
+    Traceback (most recent call last):
+    ...
+    ImportError: m5
+
+    >>> import zope.app.services.tests.test_modulelookup
+    >>> m = folder.findModule('zope.app.services.tests.test_modulelookup')
+    >>> m is zope.app.services.tests.test_modulelookup
+    1
+    
+    """
+
+def test_resolve():
+    """
+    >>> folder = MyFolder()
+    >>> import zope.app.services.tests.test_modulelookup
+    >>> f = folder.resolve(
+    ...    'zope.app.services.tests.test_modulelookup.test_resolve')
+    >>> f is zope.app.services.tests.test_modulelookup.test_resolve
+    1
+    """
+
+def test_suite(): return DocTestSuite()
+if __name__ == '__main__': unittest.main()


=== Zope3/src/zope/app/services/tests/test_adapter.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/services/tests/test_adapter.py:1.19	Sat Jun 21 17:22:13 2003
+++ Zope3/src/zope/app/services/tests/test_adapter.py	Mon Jun 30 12:37:14 2003
@@ -268,37 +268,30 @@
             r = self._service.getRegisteredMatching(*args)
             self.assertEqual(list(r), [(I1, I2, registry)])
 
-class PhonyServiceManager:
-
-    implements(IServiceService)
+class ModuleFinder:
 
     def resolve(self, name):
-        if name == 'Foo.Bar.A':
+        if name == "Foo.Bar.A":
             return A
+        raise ImportError(name)
 
-    def getService(self, name):
-        return serviceManager.getService(name)
-
-
-class TestAdapterRegistration(PlacefulSetup, TestCase):
+class TestAdapterRegistration(TestCase):
 
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-        rootFolder = RootFolder()
-        rootFolder.setServiceManager(PhonyServiceManager())
+    def test_getAdapter(self):
+        folder = ModuleFinder()
+        folder = ContextWrapper(folder, folder)
 
-        self.registration = ContextWrapper(
+        registration = ContextWrapper(
             AdapterRegistration(I1, I2, "Foo.Bar.A", "adapter"),
-            rootFolder,
+            folder,
             )
 
-    def test_getAdapter(self):
         c = C()
-        adapter = self.registration.getAdapter(c)
+        adapter = registration.getAdapter(c)
         self.assertEqual(adapter.__class__, A)
         self.assertEqual(adapter.context, c)
-        self.assertEqual(self.registration.forInterface, I1)
-        self.assertEqual(self.registration.providedInterface, I2)
+        self.assertEqual(registration.forInterface, I1)
+        self.assertEqual(registration.providedInterface, I2)
 
 def test_suite():
     return TestSuite((


=== Zope3/src/zope/app/services/tests/test_view.py 1.19 => 1.20 ===
--- Zope3/src/zope/app/services/tests/test_view.py:1.19	Tue Jun 24 11:38:04 2003
+++ Zope3/src/zope/app/services/tests/test_view.py	Mon Jun 30 12:37:14 2003
@@ -197,6 +197,7 @@
         for reg in self._service.getRegistrationsForInterface(I1E):
             self.assertEqual(reg.forInterface, I1)
 
+
 class PhonyServiceManager(ServiceManager):
 
     implements(IServiceService)
@@ -205,27 +206,33 @@
         if name == 'Foo.Bar.A':
             return A
 
-class TestViewRegistration(PlacefulSetup, TestCase):
+class ModuleFinder:
+
+    def resolve(self, name):
+        if name == "Foo.Bar.A":
+            return A
+        raise ImportError(name)
+
+
+class TestViewRegistration(TestCase):
 
-    def setUp(self):
-        PlacefulSetup.setUp(self)
-        rootFolder = RootFolder()
-        rootFolder.setServiceManager(PhonyServiceManager())
-        self.registration = ContextWrapper(
+    def test_getView(self):
+        folder = ModuleFinder()
+        folder = ContextWrapper(folder, folder)
+        registration = ContextWrapper(
             ViewRegistration(I1, 'test', IBrowserPresentation, "Foo.Bar.A",
                               'zope.View'),
-            rootFolder,
+            folder,
             )
 
-    def test_getView(self):
         c = C()
         request = TestRequest()
-        view = self.registration.getView(c, request)
+        view = registration.getView(c, request)
         self.assertEqual(view.__class__, A)
         self.assertEqual(view.context, c)
         self.assertEqual(view.request, request)
-        self.assertEqual(self.registration.forInterface, I1)
-        self.assertEqual(self.registration.presentationType, I2)
+        self.assertEqual(registration.forInterface, I1)
+        self.assertEqual(registration.presentationType, I2)
 
 
 class TestPageRegistration(PlacefulSetup, TestCase):