[Zope3-checkins] CVS: Zope3/src/zope/app/services/tests - test_modulelookup.py:1.1.2.1 test_adapter.py:1.19.6.1 test_field.py:1.8.6.1 test_module.py:1.9.6.2 test_view.py:1.19.2.1
Jim Fulton
jim@zope.com
Mon, 30 Jun 2003 07:15:52 -0400
Update of /cvs-repository/Zope3/src/zope/app/services/tests
In directory cvs.zope.org:/tmp/cvs-serv6099/src/zope/app/services/tests
Modified Files:
Tag: fdrake-local-modules-branch
test_adapter.py test_field.py test_module.py test_view.py
Added Files:
Tag: fdrake-local-modules-branch
test_modulelookup.py
Log Message:
Checkpointing to branch. Will make detailed comments in merge.
=== Added File Zope3/src/zope/app/services/tests/test_modulelookup.py ===
##############################################################################
#
# 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: test_modulelookup.py,v 1.1.2.1 2003/06/30 11:15:51 jim Exp $
"""
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.19.6.1 ===
--- 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 07:15:51 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_field.py 1.8 => 1.8.6.1 ===
--- Zope3/src/zope/app/services/tests/test_field.py:1.8 Sat Jun 7 01:32:01 2003
+++ Zope3/src/zope/app/services/tests/test_field.py Mon Jun 30 07:15:51 2003
@@ -25,23 +25,6 @@
from zope.app.interfaces.services.module import IModuleService
from zope.component.interfaces import IServiceService
-class ModuleService:
- implements(IModuleService, IServiceService)
- # I'm lying about implementing IServiceService, but that is needed to get
- # a ModuleService as a service manager. (See XXX comment in module.py.)
- def __init__(self, name=None, component=None):
- self.lookup = {}
- if name is not None:
- self.lookup[name] = component
- def resolve(self, dotted_name):
- if self.lookup.has_key(dotted_name):
- return self.lookup[dotted_name]
- raise ImportError, dotted_name
-
- def getService(self, name):
- from zope.component import getService
- return getService(None, name)
-
class I1(Interface): pass
class C:
@@ -77,70 +60,9 @@
self.assertRaises(ValidationError, field.validate, u'/folder1/d')
self.assertRaises(ValidationError, field.validate, u'/folder1/e')
-class TestComponentLocation(TestComponentPath):
-
- def createObjects(self):
- TestComponentPath.createObjects(self)
- self.resolver = ModuleService()
- self.rootFolder.setServiceManager(self.resolver)
-
- def createFields(self):
- from zope.app.services.field import ComponentLocation
-
- folder2 = traverse(self.rootFolder, 'folder2')
- field = ComponentLocation(type=I1)
- field = field.bind(folder2)
- self.field = field
- notypefield = ComponentLocation(type=None)
- notypefield = notypefield.bind(folder2)
- self.notypefield = notypefield
-
- def test__validateDottedName(self):
- field = self.notypefield
- dotted_name = u'zope.app.whatever.ClassName'
- some_class = self.__class__
- self.resolver.lookup[dotted_name] = some_class
- field._validate(dotted_name)
- self.assertRaises(ValidationError, field._validate, u'foo.bar.baz')
-
-class TestLocateComponent(PlacefulSetup, TestCase):
-
- def test_locateComponent(self):
- from zope.app.services.field import locateComponent
-
- self.buildFolders()
- self.folder1.setObject('c', C())
- self.folder1.setObject('d', D())
-
- folder2 = traverse(self.rootFolder, 'folder2')
-
- self.assertEqual(locateComponent(u'/folder1/c', folder2, I1),
- traverse(self.rootFolder, '/folder1/c')
- )
- self.assertRaises(ValidationError,
- locateComponent, u'/folder1/d', folder2, I1)
- self.assertRaises(ValidationError,
- locateComponent, u'/folder1/e', folder2)
-
- dotted_name = 'zope.app.whatever.ClassName'
- some_class = self.__class__
- resolver = ModuleService(dotted_name, some_class)
- self.rootFolder.setServiceManager(resolver)
-
- # We have to re-traverse to get new wrappers, since the old
- # wrappers have stale caches.
- folder2 = traverse(self.rootFolder, 'folder2')
-
- self.assertEqual(locateComponent(dotted_name, folder2),
- some_class
- )
- self.assertRaises(ValidationError, locateComponent, 'f.b.b', folder2)
-
def test_suite():
return TestSuite((
makeSuite(TestComponentPath),
- makeSuite(TestComponentLocation),
- makeSuite(TestLocateComponent),
))
if __name__=='__main__':
=== Zope3/src/zope/app/services/tests/test_module.py 1.9.6.1 => 1.9.6.2 ===
--- Zope3/src/zope/app/services/tests/test_module.py:1.9.6.1 Sat Jun 28 10:44:05 2003
+++ Zope3/src/zope/app/services/tests/test_module.py Mon Jun 30 07:15:51 2003
@@ -93,6 +93,10 @@
old_called = called
self.manager.source += "\n"
self.assertEqual(called, old_called)
+ m = self.manager.getModule()
+ self.assertEqual(called, old_called+1)
+ m = self.manager.getModule()
+ self.assertEqual(called, old_called+1)
=== Zope3/src/zope/app/services/tests/test_view.py 1.19 => 1.19.2.1 ===
--- 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 07:15:51 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):