[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/tests - testIContainer.py:1.5
Steve Alexander
steve@cat-box.net
Mon, 18 Nov 2002 08:34:20 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/tests
In directory cvs.zope.org:/tmp/cvs-serv443/lib/python/Zope/App/OFS/Container/tests
Modified Files:
testIContainer.py
Log Message:
Clarified the semantics of keys in an IContainer. They must be ascii
strings or unicodes.
If you want a container to make up its own key, and the container
supports this, the key must be the empty string.
I fixed a in Adding.py where this would not occur properly.
=== Zope3/lib/python/Zope/App/OFS/Container/tests/testIContainer.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/OFS/Container/tests/testIContainer.py:1.4 Wed Jul 17 12:54:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/tests/testIContainer.py Mon Nov 18 08:34:19 2002
@@ -17,7 +17,7 @@
$Id$
"""
-from unittest import TestCase, TestSuite, main, makeSuite
+from unittest import TestCase, main, makeSuite
from Zope.App.OFS.Container.IContainer import IContainer
from Interface.Verify import verifyObject
@@ -30,8 +30,8 @@
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')]:
+ 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
@@ -49,7 +49,9 @@
container = self.__setUp()
data = container.keys()
- data = list(data); data.sort() # convert to sorted list
+ # convert to sorted list
+ data = list(data)
+ data.sort()
self.assertEqual(data, map(str, range(10)))
def test_get(self):
@@ -93,7 +95,9 @@
container = self.__setUp()
data = container.items()
- data = list(data); data.sort() # convert to sorted list
+ # 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')
@@ -129,8 +133,7 @@
############################################################
# Tests from Folder
- def testEmpty( self ):
-
+ def testEmpty(self):
folder = self._Test__new()
self.failIf(folder.keys())
self.failIf(folder.values())
@@ -138,85 +141,89 @@
self.failIf(len(folder))
self.failIf('foo' in folder)
- self.assertEquals( folder.get( 'foo', None ), None )
- self.assertRaises( KeyError, folder.__getitem__, 'foo' )
+ self.assertEquals(folder.get('foo', None), None)
+ self.assertRaises(KeyError, folder.__getitem__, 'foo')
- self.assertRaises( KeyError, folder.__delitem__, 'foo' )
+ self.assertRaises(KeyError, folder.__delitem__, 'foo')
- def testOneItem( self ):
+ 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 )
+ 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.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.assertEquals(folder.get('foo', None), foo)
+ self.assertEquals(folder['foo'], foo)
- self.assertRaises( KeyError, folder.__getitem__, 'qux' )
+ self.assertRaises(KeyError, folder.__getitem__, 'qux')
foo2 = []
- folder.setObject( 'foo2', foo )
+ 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 )
+ 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(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 ):
+ 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() )
+ 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.assertEquals(len(folder), len(objects))
self.failUnless('foo' in folder)
self.failUnless('bar' in folder)
@@ -224,39 +231,39 @@
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('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' )
+ 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.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.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.assertEquals(folder.get('foo', None), None)
+ self.assertRaises(KeyError, folder.__getitem__, 'foo')
- self.assertRaises( KeyError, folder.__delitem__, '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(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)