[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - __init__.py:1.2 baseizopeitemcontainer.py:1.2 test_containertraversable.py:1.2 test_containertraverser.py:1.2 test_find.py:1.2 test_icontainer.py:1.2 test_zopecontaineradpter.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:49 -0500


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

Added Files:
	__init__.py baseizopeitemcontainer.py 
	test_containertraversable.py test_containertraverser.py 
	test_find.py test_icontainer.py test_zopecontaineradpter.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/container/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/__init__.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/container/tests/baseizopeitemcontainer.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/baseizopeitemcontainer.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,221 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from zope.proxy.context import getWrapperContainer, getWrapperData
+from zope.interface.common.tests.basemapping \
+     import BaseTestIReadMapping, BaseTestIEnumerableMapping
+from zope.app.event.tests.placelesssetup import getEvents
+from zope.app.interfaces.event \
+     import IObjectRemovedEvent, IObjectModifiedEvent, IObjectAddedEvent
+
+
+
+class BaseTestIZopeItemContainer:
+
+    def _sampleMapping(self):
+        """Return a new instance to be tested
+        """
+        raise TypeError('_new was not implemented')
+
+    def _sampleDict(self):
+        """Return a sequence of items that should be in the container
+        """
+        raise TypeError('_newItems was not implemented')
+
+    def _absentKeys(self):
+        """This should return the keys not in the container
+        """
+        absent_key = ''
+        for key, value in testItems:
+            absent_key += key
+        return [absent_key]
+
+
+    def test__getitem__(self):
+        testOb = self._sampleMapping()
+        testItems = self._sampleDict().items()
+        testAd = self._sampleContainer()
+        for key, value in testItems:
+            stored = testOb[key]
+            self.assertEqual(stored, value)
+            self.assertEqual(getWrapperContainer(stored), testAd)
+
+        for key in self._absentKeys():
+            self.assertRaises(KeyError, testOb.__getitem__, key)
+
+
+class BaseTestIZopeSimpleReadContainer(BaseTestIZopeItemContainer,
+                                       BaseTestIReadMapping):
+
+    def _IReadMapping__sample(self):
+        return self._sampleMapping()
+
+    def _IReadMapping__stateDict(self):
+        return self._sampleDict()
+
+    def _IReadMapping__absentKeys(self):
+        return self._absentKeys()
+
+    def test_zope_get(self):
+        testOb = self._sampleMapping()
+        testItems = self._sampleDict().items()
+        testAd = self._sampleContainer()
+        for key, value in testItems:
+            stored = testOb.get(key)
+            self.assertEqual(stored, value)
+            self.assertEqual(getWrapperContainer(stored), testAd)
+            self.assertEqual(getWrapperData(stored)['name'], key)
+
+
+class BaseTestIZopeReadContainer(BaseTestIZopeItemContainer,
+                                 BaseTestIEnumerableMapping):
+
+    def _IEnumerableMapping__sample(self):
+        return self._sampleMapping()
+
+    def _IEnumerableMapping__stateDict(self):
+        return self._sampleDict()
+
+    def _IEnumerableMapping__absentKeys(self):
+        return self._absentKeys()
+
+
+
+    def test_zope_values(self):
+        testOb = self._sampleMapping()
+        data = testOb.values()
+        testAd = self._sampleContainer()
+        for value in data:
+            self.assertEqual(getWrapperContainer(value), testAd)
+            getWrapperData(value)['name']
+
+
+    def test_zope_items(self):
+        testOb = self._sampleMapping()
+        testItems = self._sampleDict().items()
+        testAd = self._sampleContainer()
+        for key, value in testItems:
+            stored = testOb[key]
+            self.assertEqual(getWrapperData(stored)['name'], key)
+            self.assertEqual(value, stored)
+        self.assertEqual(testOb.items(), getWrapperContainer(stored).items())
+
+
+class BaseTestIZopeWriteContainer(BaseTestIZopeItemContainer):
+
+    def _sample_newItem(self):
+        """Return a new item key and value for testing addition
+
+        The new item must not have a IAddNotifiable adapter
+        or a IDeleteNotifyable adapter.
+        """
+        raise TypeError("_sample_newItem was not implemented")
+
+    def _sample_newItemHooked(self):
+        """Return a new item key and value for testing addition
+
+        The new item must implement IAddNotifiable
+        and IDeleteNotifyable, and must have a notified attribute that
+        is incremented when manageAfterAdd is called and decremented
+        when manage_beforeDelete is called.
+        """
+        raise TypeError("_sample_newItem was not implemented")
+
+    def test_zope_setObject(self):
+        key, value = self._sample_newItem().items()[0]
+        testOb = self._sampleMapping()
+        testAd = self._sampleContainer()
+        newkey = testOb.setObject(key, value)
+        self.assertEqual(testOb[newkey], value)
+
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectAddedEvent)
+             if event.object == value]
+             )
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectModifiedEvent)
+             if event.object == testAd]
+             )
+
+        key, value = self._sample_newItemHooked().items()[0]
+        oldnotified = value.notified +1
+        newkey = testOb.setObject(key, value)
+        self.assertEqual(value.notified , oldnotified)
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectAddedEvent)
+             if event.object == value]
+             )
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectModifiedEvent)
+             if event.object == testAd]
+             )
+
+
+
+    def test__zope_delitem__(self):
+        testOb = self._sampleMapping()
+        testObHook = self._sample_newItemHooked()
+        testAd = self._sampleContainer()
+        self.assertRaises(KeyError, testOb.__delitem__, 'zc')
+        key, value = self._sample_newItem()
+        newkey = testOb.setObject(key, value)
+        del testOb[key]
+        self.assertRaises(KeyError, testOb.__delitem__, key)
+
+
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectRemovedEvent)
+             if event.object == value]
+             )
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectModifiedEvent)
+             if event.object == testAd]
+             )
+
+        key, value = self._sample_newItemHooked().items()[0]
+        newkey = testOb.setObject(key, value)
+        oldnotified = value.notified - 1
+        del testOb[key]
+        self.assertRaises(KeyError, testOb.__delitem__, key)
+
+        self.assertEqual(value.notified , oldnotified)
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectRemovedEvent)
+             if event.object == value]
+             )
+
+        self.failUnless(
+            [event
+             for event in getEvents(IObjectModifiedEvent)
+             if event.object == testAd]
+             )


=== Zope3/src/zope/app/container/tests/test_containertraversable.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/test_containertraversable.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,71 @@
+##############################################################################
+#
+# 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$
+"""
+
+import unittest, sys
+from zope.app.container.traversal import ContainerTraversable
+from zope.exceptions import NotFoundError
+from zope.app.interfaces.container import IContainer
+from zope.testing.cleanup import CleanUp
+
+
+class Container:
+
+    __implements__ = IContainer
+
+    def __init__(self, attrs={}, objs={}):
+        for attr,value in attrs.iteritems():
+            setattr(self, attr, value)
+
+        self.__objs = {}
+        for name,value in objs.iteritems():
+            self.__objs[name] = value
+
+
+    def __getitem__(self, name):
+        return self.__objs[name]
+
+    def get(self, name, default=None):
+        return self.__objs.get(name, default)
+
+    def __contains__(self, name):
+        return self.__objs.has_key(name)
+
+
+class Test(CleanUp, unittest.TestCase):
+    def testAttr(self):
+        # test container path traversal
+        foo = Container()
+        bar = Container()
+        baz = Container()
+        c   = Container( {'foo':foo}, {'bar':bar, 'foo':baz} )
+
+        T = ContainerTraversable(c)
+        self.failUnless(T.traverse('foo', (), 'foo', []) is baz)
+        self.failUnless(T.traverse('bar', (), 'bar', []) is bar)
+
+        self.assertRaises(NotFoundError , T.traverse,
+                          'morebar', (), 'morebar', [])
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/container/tests/test_containertraverser.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/test_containertraverser.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,90 @@
+##############################################################################
+#
+# 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$
+"""
+
+import unittest, sys
+from zope.component.tests.request import Request
+from zope.component import getService
+from zope.app.container.traversal import ContainerTraverser
+from zope.interface import Interface
+from zope.exceptions import NotFoundError
+from zope.app.interfaces.container import IContainer
+from zope.app.tests.placelesssetup import PlacelessSetup
+
+class I(Interface):
+    pass
+
+
+class Container:
+    __implements__ = IContainer
+
+    def __init__(self, **kw):
+        for k in kw:
+            setattr(self, k , kw[k])
+
+    def get(self, name, default=None):
+        return getattr(self, name, default)
+
+
+
+class Request(Request):
+    def getEffectiveURL(self):
+        return ''
+
+
+class View:
+    def __init__(self, comp, request):
+        self._comp = comp
+
+
+class Test(PlacelessSetup, unittest.TestCase):
+    def testAttr(self):
+        # test container traver
+        foo = Container()
+        c   = Container( foo=foo )
+        req = Request( I, '')
+
+        T = ContainerTraverser(c, req)
+        self.failUnless(T.publishTraverse(req,'foo') is foo)
+
+        self.assertRaises(NotFoundError , T.publishTraverse, req ,'morebar')
+
+
+    def testView(self):
+        # test getting a view
+        foo = Container()
+        c   = Container( foo=foo )
+        req = Request( I, '')
+
+        T = ContainerTraverser(c, req)
+        getService(None,'Views').provideView(IContainer, 'viewfoo', I, [View])
+
+        self.failUnless(T.publishTraverse(req,'viewfoo').__class__ is View )
+        self.failUnless(T.publishTraverse(req,'foo') is foo)
+
+        self.assertRaises(NotFoundError , T.publishTraverse, req, 'morebar')
+        self.assertRaises(NotFoundError , T.publishTraverse, req,
+                          '@@morebar')
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/container/tests/test_find.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/test_find.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,150 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.interfaces.container import IReadContainer
+from zope.app.interfaces.container.find import IObjectFindFilter
+from zope.app.container.find\
+     import FindAdapter, SimpleIdFindFilter
+
+class FakeContainer:
+    __implements__ = IReadContainer
+
+    def __init__(self, id, objects):
+        self._id = id
+        self._objects = objects
+
+    def keys(self):
+        return [object._id for object in self._objects]
+
+    def values(self):
+        return self._objects
+
+    def items(self):
+        return [(object._id, object) for object in self._objects]
+
+    def __getitem__(self, id):
+        for object in self._objects:
+            if object._id == id:
+                return object
+        raise KeyError, "Could not find %s" % id
+
+    def get(self, id, default=None):
+        for object in self._objects:
+            if object._id == id:
+                return object
+
+        return default
+
+    def __contains__(self, id):
+        for object in self._objects:
+            if object.id == id:
+                return 1
+        return 0
+
+    def __len__(self):
+        return len(self._objects)
+
+class TestObjectFindFilter(object):
+    __implements__ = IObjectFindFilter
+
+    def __init__(self, count):
+        self._count = count
+
+    def matches(self, object):
+        if IReadContainer.isImplementedBy(object):
+            return len(object) == self._count
+        else:
+            return 0
+
+class Test(TestCase):
+    def test_idFind(self):
+        alpha = FakeContainer('alpha', [])
+        delta = FakeContainer('delta', [])
+        beta = FakeContainer('beta', [delta])
+        gamma = FakeContainer('gamma', [])
+        tree = FakeContainer(
+            'tree',
+            [alpha, beta, gamma])
+        find = FindAdapter(tree)
+        # some simple searches
+        result = find.find([SimpleIdFindFilter(['beta'])])
+        self.assertEquals([beta], result)
+        result = find.find([SimpleIdFindFilter(['gamma'])])
+        self.assertEquals([gamma], result)
+        result = find.find([SimpleIdFindFilter(['delta'])])
+        self.assertEquals([delta], result)
+        # we should not find the container we search on
+        result = find.find([SimpleIdFindFilter(['tree'])])
+        self.assertEquals([], result)
+        # search for multiple ids
+        result = find.find([SimpleIdFindFilter(['alpha', 'beta'])])
+        self.assertEquals([alpha, beta], result)
+        result = find.find([SimpleIdFindFilter(['beta', 'delta'])])
+        self.assertEquals([beta, delta], result)
+        # search without any filters, find everything
+        result = find.find([])
+        self.assertEquals([alpha, beta, delta, gamma], result)
+        # search for something that doesn't exist
+        result = find.find([SimpleIdFindFilter(['foo'])])
+        self.assertEquals([], result)
+        # find for something that has two ids at the same time,
+        # can't ever be the case
+        result = find.find([SimpleIdFindFilter(['alpha']),
+                            SimpleIdFindFilter(['beta'])])
+        self.assertEquals([], result)
+
+    def test_objectFind(self):
+        alpha = FakeContainer('alpha', [])
+        delta = FakeContainer('delta', [])
+        beta = FakeContainer('beta', [delta])
+        gamma = FakeContainer('gamma', [])
+        tree = FakeContainer(
+            'tree',
+            [alpha, beta, gamma])
+        find = FindAdapter(tree)
+        result = find.find(object_filters=[TestObjectFindFilter(0)])
+        self.assertEquals([alpha, delta, gamma], result)
+        result = find.find(object_filters=[TestObjectFindFilter(1)])
+        self.assertEquals([beta], result)
+        result = find.find(object_filters=[TestObjectFindFilter(2)])
+        self.assertEquals([], result)
+
+    def test_combinedFind(self):
+        alpha = FakeContainer('alpha', [])
+        delta = FakeContainer('delta', [])
+        beta = FakeContainer('beta', [delta])
+        gamma = FakeContainer('gamma', [])
+        tree = FakeContainer(
+            'tree',
+            [alpha, beta, gamma])
+        find = FindAdapter(tree)
+        result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])],
+                           object_filters=[TestObjectFindFilter(0)])
+        self.assertEquals([alpha], result)
+
+        result = find.find(id_filters=[SimpleIdFindFilter(['alpha'])],
+                           object_filters=[TestObjectFindFilter(1)])
+        self.assertEquals([], result)
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/container/tests/test_icontainer.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:48 2002
+++ Zope3/src/zope/app/container/tests/test_icontainer.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,282 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+
+Revision information:
+$Id$
+"""
+
+from unittest import TestCase, main, makeSuite
+from zope.app.interfaces.container import IContainer
+from zope.interface.verify import verifyObject
+
+class BaseTestIContainer:
+    """Base test cases for containers.
+
+    Subclasses need to define a method, '_Test__new', that
+    takes no arguments and that returns a new empty test container.
+    """
+
+    def __setUp(self):
+        self.__container = container = self._Test__new()
+        for k,v in [('3', '0'), ('2', '1'), ('4', '2'), ('6', '3'), ('0', '4'),
+                    ('5', '5'), ('1', '6'), ('8', '7'), ('7', '8'), ('9', '9')]:
+            container.setObject(k, v)
+        return container
+
+    ############################################################
+    # Interface-driven tests:
+
+    def testIContainerVerify(self):
+        verifyObject(IContainer, self._Test__new())
+
+    def test_keys(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        data = container.keys()
+        self.assertEqual(list(data), [])
+
+        container = self.__setUp()
+        data = container.keys()
+        # convert to sorted list
+        data = list(data)
+        data.sort()
+        self.assertEqual(data, map(str, range(10)))
+
+    def test_get(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        self.assertRaises(KeyError, container.__getitem__, '1')
+        self.assertEqual(container.get('1', '99'), '99')
+
+        container = self.__setUp()
+        self.assertRaises(KeyError, container.__getitem__, '100')
+        self.assertEqual(container.get('100', '99'), '99')
+        self.assertEqual(container.get('1', '99'), '6')
+        self.assertEqual(container['7'], '8')
+        self.assertEqual(container['0'], '4')
+        self.assertEqual(container['9'], '9')
+
+    def test_values(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        data = container.values()
+        self.assertEqual(list(data), [])
+
+        container = self.__setUp()
+        data = container.values()
+        data = list(data); data.sort() # convert to sorted list
+        self.assertEqual(data, map(str, range(10)))
+
+    def test_len(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        self.assertEqual(len(container), 0)
+
+        container = self.__setUp()
+        self.assertEqual(len(container), 10)
+
+    def test_items(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        data = container.items()
+        self.assertEqual(list(data), [])
+
+        container = self.__setUp()
+        data = container.items()
+        # convert to sorted list
+        data = list(data)
+        data.sort()
+        self.assertEqual(data, [
+            ('0', '4'), ('1', '6'), ('2', '1'), ('3', '0'), ('4', '2'),
+            ('5', '5'), ('6', '3'), ('7', '8'), ('8', '7'), ('9', '9')
+            ])
+
+    def test___contains__(self):
+        # See interface IReadContainer
+        container = self._Test__new()
+        self.assertEqual(not not ('1' in container), 0)
+
+        container = self.__setUp()
+        self.assertEqual(not not ('100' in container), 0)
+        self.assertEqual(not not ('1' in container), 1)
+        self.assertEqual(not not ('0' in container), 1)
+        self.assertEqual(not not ('9' in container), 1)
+
+    def test_delObject(self):
+        # See interface IWriteContainer
+        container = self._Test__new()
+        self.assertRaises(KeyError, container.__delitem__, '1')
+
+        container = self.__setUp()
+        self.assertRaises(KeyError, container.__delitem__, '100')
+        del container['1']
+        del container['9']
+        self.assertRaises(KeyError, container.__getitem__, '1')
+        self.assertRaises(KeyError, container.__getitem__, '9')
+        self.assertEqual(container.get('1', '99'), '99')
+        self.assertEqual(container['7'], '8')
+        self.assertEqual(container['0'], '4')
+        self.assertEqual(container.get('9', '88'), '88')
+
+    ############################################################
+    # Tests from Folder
+
+    def testEmpty(self):
+        folder = self._Test__new()
+        self.failIf(folder.keys())
+        self.failIf(folder.values())
+        self.failIf(folder.items())
+        self.failIf(len(folder))
+        self.failIf('foo' in folder)
+
+        self.assertEquals(folder.get('foo', None), None)
+        self.assertRaises(KeyError, folder.__getitem__, 'foo')
+
+        self.assertRaises(KeyError, folder.__delitem__, 'foo')
+
+    def testBadKeyTypes(self):
+        folder = self._Test__new()
+        value = []
+        self.assertRaises(TypeError, folder.setObject, None, value)
+        self.assertRaises(TypeError, folder.setObject, ['foo'], value)
+
+    def testOneItem(self):
+        folder = self._Test__new()
+        foo = []
+        folder.setObject('foo', foo)
+
+        self.assertEquals(len(folder.keys()), 1)
+        self.assertEquals(folder.keys()[0], 'foo')
+        self.assertEquals(len(folder.values()), 1)
+        self.assertEquals(folder.values()[0], foo)
+        self.assertEquals(len(folder.items()), 1)
+        self.assertEquals(folder.items()[0], ('foo', foo))
+        self.assertEquals(len(folder), 1)
+
+        self.failUnless('foo' in folder)
+        self.failIf('bar' in folder)
+
+        self.assertEquals(folder.get('foo', None), foo)
+        self.assertEquals(folder['foo'], foo)
+
+        self.assertRaises(KeyError, folder.__getitem__, 'qux')
+
+        foo2 = []
+        folder.setObject('foo2', foo)
+
+        self.assertEquals(len(folder.keys()), 2)
+        self.assertEquals(folder.keys()[1], 'foo2')
+        self.assertEquals(len(folder.values()), 2)
+        self.assertEquals(folder.values()[1], foo2)
+        self.assertEquals(len(folder.items()), 2)
+        self.assertEquals(folder.items()[1], ('foo2', foo2))
+        self.assertEquals(len(folder), 2)
+
+        del folder['foo']
+        del folder['foo2']
+
+        self.failIf(folder.keys())
+        self.failIf(folder.values())
+        self.failIf(folder.items())
+        self.failIf(len(folder))
+        self.failIf('foo' in folder)
+
+        self.assertRaises(KeyError, folder.__getitem__, 'foo')
+        self.assertEquals(folder.get('foo', None), None)
+        self.assertRaises(KeyError, folder.__delitem__, 'foo')
+
+    def testManyItems(self):
+        folder = self._Test__new()
+        objects = [ [0], [1], [2], [3] ]
+        folder.setObject('foo', objects[0])
+        folder.setObject('bar', objects[1])
+        folder.setObject('baz', objects[2])
+        folder.setObject('bam', objects[3])
+
+        self.assertEquals(len(folder.keys()), len(objects))
+        self.failUnless('foo' in folder.keys())
+        self.failUnless('bar' in folder.keys())
+        self.failUnless('baz' in folder.keys())
+        self.failUnless('bam' in folder.keys())
+
+        self.assertEquals(len(folder.values()), len(objects))
+        self.failUnless(objects[0] in folder.values())
+        self.failUnless(objects[1] in folder.values())
+        self.failUnless(objects[2] in folder.values())
+        self.failUnless(objects[3] in folder.values())
+
+        self.assertEquals(len(folder.items()), len(objects))
+        self.failUnless(('foo', objects[0]) in folder.items())
+        self.failUnless(('bar', objects[1]) in folder.items())
+        self.failUnless(('baz', objects[2]) in folder.items())
+        self.failUnless(('bam', objects[3]) in folder.items())
+
+        self.assertEquals(len(folder), len(objects))
+
+        self.failUnless('foo' in folder)
+        self.failUnless('bar' in folder)
+        self.failUnless('baz' in folder)
+        self.failUnless('bam' in folder)
+        self.failIf('qux' in folder)
+
+        self.assertEquals(folder.get('foo', None), objects[0])
+        self.assertEquals(folder['foo'], objects[0])
+        self.assertEquals(folder.get('bar', None), objects[1])
+        self.assertEquals(folder['bar'], objects[1])
+        self.assertEquals(folder.get('baz', None), objects[2])
+        self.assertEquals(folder['baz'], objects[2])
+        self.assertEquals(folder.get('bam', None), objects[3])
+        self.assertEquals(folder['bam'], objects[3])
+
+        self.assertEquals(folder.get('qux', None), None)
+        self.assertRaises(KeyError, folder.__getitem__, 'qux')
+
+        del folder['foo']
+        self.assertEquals(len(folder), len(objects) - 1)
+        self.failIf('foo' in folder)
+        self.failIf('foo' in folder.keys())
+
+        self.failIf(objects[0] in folder.values())
+        self.failIf(('foo', objects[0]) in folder.items())
+
+        self.assertEquals(folder.get('foo', None), None)
+        self.assertRaises(KeyError, folder.__getitem__, 'foo')
+
+        self.assertRaises(KeyError, folder.__delitem__, 'foo')
+
+        del folder['bar']
+        del folder['baz']
+        del folder['bam']
+
+        self.failIf(folder.keys())
+        self.failIf(folder.values())
+        self.failIf(folder.items())
+        self.failIf(len(folder))
+        self.failIf('foo' in folder)
+        self.failIf('bar' in folder)
+        self.failIf('baz' in folder)
+        self.failIf('bam' in folder)
+
+
+class Test(BaseTestIContainer, TestCase):
+    def _Test__new(self):
+        from zope.app.container.sample import SampleContainer
+        return SampleContainer()
+
+def test_suite():
+    return makeSuite(Test)
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/app/container/tests/test_zopecontaineradpter.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:49 2002
+++ Zope3/src/zope/app/container/tests/test_zopecontaineradpter.py	Wed Dec 25 09:12:47 2002
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.app.interfaces.container import IAddNotifiable
+from zope.app.interfaces.container import IDeleteNotifiable
+from zope.app.container.tests.baseizopeitemcontainer \
+     import BaseTestIZopeItemContainer, BaseTestIZopeSimpleReadContainer,\
+            BaseTestIZopeReadContainer, BaseTestIZopeWriteContainer
+from zope.app.traversing import getParent
+from zope.proxy.context import ContextWrapper
+from zope.app.tests.placelesssetup import PlacelessSetup
+class C: pass
+
+class H:
+    __implements__ = IAddNotifiable, IDeleteNotifiable
+    notified = 0
+    def manage_beforeDelete(self, object, container):
+        self.notified -= 1
+
+
+    def manage_afterAdd(self, object, container):
+        self.notified += 1
+
+class Test(PlacelessSetup,
+           BaseTestIZopeSimpleReadContainer,
+           BaseTestIZopeReadContainer,
+           BaseTestIZopeWriteContainer,
+           TestCase):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+        from zope.app.container.sample import SampleContainer
+        self.__container = SampleContainer()
+
+    def _sampleMapping(self):
+        from zope.app.container.zopecontainer \
+            import ZopeContainerAdapter
+        container = self.__container
+        for k, v in self._sampleDict().items():
+            container.setObject(k, v)
+        return ZopeContainerAdapter(container)
+
+    def _sampleContainer(self):
+        return self.__container
+
+    __sample = {'Z': C(), 'O': C(),'P': C()}
+    def _sampleDict(self):
+        return self.__sample
+
+
+    def _absentKeys(self):
+        return 'zc', 'ny'
+
+    __newItem = {'A': C(), 'B':C()}
+    def _sample_newItem(self):
+        return self.__newItem
+
+    __newItemHooked = {'B': H(), 'E':H()}
+    def _sample_newItemHooked(self):
+        return self.__newItemHooked
+
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')