[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Memento/tests - MementoBag.py:1.1.2.1 __init__.py:1.1.2.1 testAttributeMementoBag.py:1.1.2.1
R. David Murray
rdmurray@bitdance.com
Sat, 23 Mar 2002 13:03:28 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Memento/tests
In directory cvs.zope.org:/tmp/cvs-serv16085/lib/python/Zope/App/OFS/Memento/tests
Added Files:
Tag: Zope-3x-branch
MementoBag.py __init__.py testAttributeMementoBag.py
Log Message:
Implementation of AttributeMementoBag from Tres Sever's proposal at
ComponentArchitecture/MementoBagProposal, as modified by Jim's comments
about the use of dotted names rather than a key registry.
R. David Murray (rdmurray) and Nikheel Dhekne (ndhekne).
=== Added File Zope3/lib/python/Zope/App/OFS/Memento/tests/MementoBag.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
#
##############################################################################
"""
Revision information:
$Id: MementoBag.py,v 1.1.2.1 2002/03/23 18:03:27 rdmurray Exp $
"""
class MementoBag:
"Test the IMementoBag interface"
def setUp(self):
self.obj = {1: 2, 3: 4}
def testStorage(self):
"""test __getitem__"""
self.bag['unittest'] = self.obj
res = self.bag['unittest']
self.failUnlessEqual(self.obj,res)
def testGetitemException(self):
"""test __getitem raises exception on unknown key"""
self.assertRaises(KeyError,self.bag.__getitem__,'randomkey')
def testGet(self):
"""test get"""
self.bag['unittest'] = obj
res = self.bag.get('unittest')
self.failUnlessEqual(obj,res)
def testGet(self):
"""test get with no set"""
res = self.bag.get('randomkey')
self.failUnlessEqual(None,res)
def testGetDefault(self):
"""test get returns default"""
res = self.bag.get('randomkey','default')
self.failUnlessEqual('default',res)
def testDel(self):
self.bag['unittest'] = self.obj
del self.bag['unittest']
self.failUnlessEqual(None,self.bag.get('unittest'))
def testDelRaisesKeyError(self):
self.assertRaises(KeyError,self.bag.__delitem__,'unittest')
=== Added File Zope3/lib/python/Zope/App/OFS/Memento/tests/__init__.py ===
=== Added File Zope3/lib/python/Zope/App/OFS/Memento/tests/testAttributeMementoBag.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
#
##############################################################################
"""
Revision information:
$Id: testAttributeMementoBag.py,v 1.1.2.1 2002/03/23 18:03:27 rdmurray Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from MementoBag import MementoBag
from Zope.App.OFS.Memento.AttributeMementoBag import AttributeMementoBag
from Zope.App.OFS.Memento.IAttributeMementoStorable \
import IAttributeMementoStorable
class Dummy:
__implements__ = IAttributeMementoStorable
class Test(CleanUp, MementoBag, TestCase):
def setUp(self):
self.bag = AttributeMementoBag(Dummy())
#super(Test,self).setUp()
MementoBag.setUp(self)
CleanUp.setUp(self)
def test_suite():
return TestSuite((
makeSuite(Test),
))
if __name__=='__main__':
main(defaultTest='test_suite')