[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing/tests - testPhysicalLocationAdapters.py:1.1 testConvenienceFunctions.py:1.4 testTraverser.py:1.4

Jim Fulton jim@zope.com
Thu, 11 Jul 2002 14:22:06 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing/tests
In directory cvs.zope.org:/tmp/cvs-serv7355/lib/python/Zope/App/Traversing/tests

Modified Files:
	testConvenienceFunctions.py testTraverser.py 
Added Files:
	testPhysicalLocationAdapters.py 
Log Message:

Reimplemented service managers to be package based. Service managers
are no longer containers. They have a packages subobject (not a
packages service) that contains packages. TTW components are created
in packages. To register a component, create the appropriate component
directive objects (these should be called configuration objects).

This should be viewed as a prototype to illustrate the idea of
packages. Lots of things can change (especially UI) and many things
aren't done (e.g. visiting created directives).

In the course of this, I fixed a bunch of bugs and problems in
traversal machinery. 

I also renamed Zope.ComponentArchitecture.IServiceManager back to
IServiceService, since this interface doesn't actually specify any
management.  



=== Added File Zope3/lib/python/Zope/App/Traversing/tests/testPhysicalLocationAdapters.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""
$Id: testPhysicalLocationAdapters.py,v 1.1 2002/07/11 18:21:34 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
from Zope.ComponentArchitecture import getAdapter

from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
from Zope.App.Traversing.PhysicalLocationAdapters \
     import WrapperPhysicallyLocatable, RootPhysicallyLocatable
from Zope.Proxy.ContextWrapper import ContextWrapper

class Root: __implements__ = IContainmentRoot
class C: pass

class Test(PlacelessSetup, TestCase):

    def test(self):
        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
        provideAdapter(IContainmentRoot, IPhysicallyLocatable,
                       RootPhysicallyLocatable)

        root = Root()
        f1 = ContextWrapper(C(), root, name='f1')
        f2 = ContextWrapper(C(),   f1, name='f2')
        f3 = ContextWrapper(C(),   f2, name='f3')

        adapter = getAdapter(f3, IPhysicallyLocatable)

        self.assertEqual(adapter.getPhysicalPath(), ('', 'f1', 'f2', 'f3'))
        self.assertEqual(adapter.getPhysicalRoot(), root)
        
        adapter = getAdapter(C(), IPhysicallyLocatable)
        self.assertRaises(TypeError, adapter.getPhysicalPath)
        self.assertRaises(TypeError, adapter.getPhysicalRoot)

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')







=== Zope3/lib/python/Zope/App/Traversing/tests/testConvenienceFunctions.py 1.3 => 1.4 ===
 from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.App.Traversing.Traverser import Traverser
 from Zope.ComponentArchitecture import getService
+
 from Zope.App.Traversing.ITraverser import ITraverser
 from Zope.App.Traversing.ITraversable import ITraversable
 from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
 from Zope.App.Traversing.ObjectName import IObjectName, ObjectName
+
+from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
+from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
+from Zope.App.Traversing.PhysicalLocationAdapters \
+     import WrapperPhysicallyLocatable, RootPhysicallyLocatable
+
+
 from Zope.Exceptions import NotFoundError
 
 class C:
@@ -37,10 +45,11 @@
         PlacefulSetup.setUp(self)
         # Build up a wrapper chain
         root = C('root')
+        root.__implements__ = IContainmentRoot
         folder = C('folder')
         item = C('item')
         
-        self.root =   ContextWrapper(root,   None,        name='')
+        self.root =   root
         self.folder = ContextWrapper(folder, self.root,   name='folder')
         self.item =   ContextWrapper(item,   self.folder, name='item')
         self.unwrapped_item = item
@@ -49,12 +58,16 @@
         folder.item = item
 
         self.tr = Traverser(root)
-        getService(None,"Adapters").provideAdapter(
+        getService(None, "Adapters").provideAdapter(
               None, ITraverser, Traverser)
-        getService(None,"Adapters").provideAdapter(
+        getService(None, "Adapters").provideAdapter(
               None, ITraversable, DefaultTraversable)
-        getService(None,"Adapters").provideAdapter(
+        getService(None, "Adapters").provideAdapter(
               None, IObjectName, ObjectName)
+        getService(None, "Adapters").provideAdapter(
+              None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        getService(None, "Adapters").provideAdapter(
+              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
 
 
     def testTraverse(self):
@@ -81,15 +94,6 @@
         self.assertEqual(
             traverseName(self.item, '.'),
             self.tr.traverse('/folder/item')
-            )
-
-            
-    def testTraverseNameUnwrapped(self):
-        from Zope.App.Traversing import traverseName
-        self.assertRaises(
-            TypeError,
-            traverseName,
-            self.unwrapped_item, 'item'
             )
             
     def testTraverseNameBadValue(self):


=== Zope3/lib/python/Zope/App/Traversing/tests/testTraverser.py 1.3 => 1.4 ===
 from Zope.App.Traversing.ITraversable import ITraversable
 from Zope.App.Traversing.Traverser import Traverser
 from Zope.App.Traversing.DefaultTraversable import DefaultTraversable
+
+from Zope.App.Traversing.IPhysicallyLocatable import IPhysicallyLocatable
+from Zope.App.Traversing.IContainmentRoot import IContainmentRoot
+from Zope.App.Traversing.PhysicalLocationAdapters \
+     import WrapperPhysicallyLocatable, RootPhysicallyLocatable
+
 from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.Exceptions import NotFoundError, Unauthorized
 from Zope.ComponentArchitecture import getService
@@ -44,7 +50,7 @@
     def setUp(self):
         PlacefulSetup.setUp(self)
         # Build up a wrapper chain
-        self.root =   ContextWrapper(C('root'),   None,        name='')
+        self.root =   C('root')
         self.folder = ContextWrapper(C('folder'), self.root,   name='folder')
         self.item =   ContextWrapper(C('item'),   self.folder, name='item')
         self.tr = Traverser(self.item)
@@ -56,22 +62,10 @@
         for interface in instancesOfObjectImplements(Traverser):
             verifyClass(interface, Traverser)
 
-    def testPhysicalRoot(self):
-        self.failUnless(self.tr.getPhysicalRoot() is self.root)
-
-    def testPhysicalPath(self):
-        self.assertEquals(self.tr.getPhysicalPath(), ('', 'folder', 'item'))
-
-    def testUnwrapped(self):
-        # The feature should do the right thing for unwrapped objects too
-        unwrapped = C('unwrapped')
-        tr = Traverser(unwrapped)
-        self.assertEquals(tr.getPhysicalPath(), ())
-        self.failUnless(tr.getPhysicalRoot() is unwrapped)
-
 class UnrestrictedNoTraverseTests(unittest.TestCase):
     def setUp(self):
         self.root = root = C('root')
+        self.root.__implements__ = IContainmentRoot
         self.folder = folder = C('folder')
         self.item = item = C('item')
 
@@ -89,10 +83,15 @@
         PlacefulSetup.setUp(self)
         # Build up a wrapper chain
 
-        getService(None,"Adapters").provideAdapter(
+        getService(None, "Adapters").provideAdapter(
               None, ITraversable, DefaultTraversable)
+        getService(None, "Adapters").provideAdapter(
+              None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        getService(None, "Adapters").provideAdapter(
+              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
 
         self.root = root = C('root')
+        self.root.__implements__ = IContainmentRoot
         self.folder = folder = C('folder')
         self.item = item = C('item')
 
@@ -160,8 +159,13 @@
 
         getService(None,"Adapters").provideAdapter(
              None, ITraversable, DefaultTraversable)
+        getService(None, "Adapters").provideAdapter(
+              None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        getService(None, "Adapters").provideAdapter(
+              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
 
         self.root = root = C('root')
+        root.__implements__ = IContainmentRoot
         self.folder = folder = C('folder')
         self.item = item = C('item')