[Zope3-checkins] CVS: Zope3/src/zope/app/container/tests - baseizopeitemcontainer.py:1.5 test_zopecontainer.py:1.2
Steve Alexander
steve@cat-box.net
Sun, 15 Jun 2003 12:10:44 -0400
Update of /cvs-repository/Zope3/src/zope/app/container/tests
In directory cvs.zope.org:/tmp/cvs-serv18616/src/zope/app/container/tests
Modified Files:
baseizopeitemcontainer.py test_zopecontainer.py
Log Message:
Added ZopeContainerDecorators for all kinds of container.
One notable feature is that an IItemContainer is decorated to become
an IZopeSimpleReadContainer. The decorator implements ISimpleReadContainer
in terms of IItemContainer.
=== Zope3/src/zope/app/container/tests/baseizopeitemcontainer.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/container/tests/baseizopeitemcontainer.py:1.4 Tue May 27 10:18:13 2003
+++ Zope3/src/zope/app/container/tests/baseizopeitemcontainer.py Sun Jun 15 12:10:43 2003
@@ -25,7 +25,6 @@
import IObjectRemovedEvent, IObjectModifiedEvent, IObjectAddedEvent
-
class BaseTestIZopeItemContainer:
def _sampleMapping(self):
@@ -41,6 +40,7 @@
def _absentKeys(self):
"""This should return the keys not in the container
"""
+ # XXX Is this supposed to be pseudocode? It doesn't make sense.
absent_key = ''
for key, value in testItems:
absent_key += key
=== Zope3/src/zope/app/container/tests/test_zopecontainer.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/container/tests/test_zopecontainer.py:1.1 Wed Jun 4 10:57:57 2003
+++ Zope3/src/zope/app/container/tests/test_zopecontainer.py Sun Jun 15 12:10:43 2003
@@ -38,35 +38,94 @@
def afterAddHook(self, object, container):
self.notified += 1
-class Test(PlacelessSetup,
- BaseTestIZopeSimpleReadContainer,
- BaseTestIZopeReadContainer,
- BaseTestIZopeWriteContainer,
- TestCase):
+class ItemContainer:
+ "Container that implements only __getitem__ for reading."
+
+ def __init__(self):
+ self._d = {}
+
+ def __getitem__(self, key):
+ return self._d[key]
+
+ def __setitem__(self, key, value):
+ self._d[key] = value
+
+class TestZopeItemContainerDecorator(PlacelessSetup,
+ BaseTestIZopeSimpleReadContainer,
+ TestCase):
+ # Note that this test derives from BaseTestIZopeSimpleReadContainer.
+ # This is because the ZopeItemContainerDecorator decorates IItemContainer,
+ # and as well as providing context-awareness, it upgrades IItemContainer
+ # to ISimpleReadContainer.
def setUp(self):
PlacelessSetup.setUp(self)
- from zope.app.container.sample import SampleContainer
- self.__container = SampleContainer()
+ self._container = ItemContainer()
+
+ def decorate(self, container):
+ from zope.app.container.zopecontainer import ZopeItemContainerDecorator
+ return ZopeItemContainerDecorator(container)
def _sampleMapping(self):
- from zope.app.container.zopecontainer import ZopeContainerDecorator
- container = self.__container
+ container = self._container
for k, v in self._sampleDict().items():
- container.setObject(k, v)
- return ZopeContainerDecorator(container)
+ container[k] = v
+ return self.decorate(container)
def _sampleContainer(self):
- return self.__container
+ return self._container
- __sample = {'Z': C(), 'O': C(),'P': C()}
+ _sample = {'Z': C(), 'O': C(),'P': C()}
def _sampleDict(self):
- return self.__sample
-
+ return self._sample
def _absentKeys(self):
return 'zc', 'ny'
+class TestZopeSimpleReadContainerDecorator(TestZopeItemContainerDecorator,
+ BaseTestIZopeSimpleReadContainer):
+
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+ self._container = {}
+
+ def decorate(self, container):
+ from zope.app.container.zopecontainer import \
+ ZopeSimpleReadContainerDecorator
+ return ZopeSimpleReadContainerDecorator(container)
+
+class TestZopeReadContainerDecorator(TestZopeSimpleReadContainerDecorator,
+ BaseTestIZopeReadContainer):
+
+ def decorate(self, container):
+ from zope.app.container.zopecontainer import \
+ ZopeReadContainerDecorator
+ return ZopeReadContainerDecorator(container)
+
+class TestZopeWriteContainerDecorator(TestZopeItemContainerDecorator,
+ BaseTestIZopeWriteContainer):
+ # The ZopeWriteContainerDecorator depends on the container also being
+ # an IItemContainer. It needs this to get values that are to be deleted
+ # so they can be sent in events.
+ # So, this unit test tests that the decorator implementation properly
+ # decorates IZopeItemContainer and IZopeWriteContainer.
+
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+ from zope.app.container.sample import SampleContainer
+ self._container = SampleContainer()
+
+ def _sampleMapping(self):
+ container = self._container
+ for k, v in self._sampleDict().items():
+ container.setObject(k, v)
+ return self.decorate(container)
+
+ def decorate(self, container):
+ from zope.app.container.zopecontainer import \
+ ZopeWriteContainerDecorator
+ return ZopeWriteContainerDecorator(container)
+
__newItem = {'A': C(), 'B':C()}
def _sample_newItem(self):
return self.__newItem
@@ -76,9 +135,20 @@
return self.__newItemHooked
+class TestZopeContainerDecorator(TestZopeWriteContainerDecorator):
+
+ def decorate(self, container):
+ from zope.app.container.zopecontainer import ZopeContainerDecorator
+ return ZopeContainerDecorator(container)
+
+
def test_suite():
return TestSuite((
- makeSuite(Test),
+ makeSuite(TestZopeItemContainerDecorator),
+ makeSuite(TestZopeSimpleReadContainerDecorator),
+ makeSuite(TestZopeReadContainerDecorator),
+ makeSuite(TestZopeWriteContainerDecorator),
+ makeSuite(TestZopeContainerDecorator),
))
if __name__=='__main__':