Commit 0f8dc288 authored by Tres Seaver's avatar Tres Seaver

PersistentMapping was inadvertently pickling volatile attributes...

PersistentMapping was inadvertently pickling volatile attributes (http://www.zope.org/Collectors/Zope/2052).

parent 035f4627
......@@ -59,6 +59,9 @@ persistent
- (3.7a1) Suppressed warnings about signedness of characters when
compiling under GCC 4.0.x. See http://www.zope.org/Collectors/Zope/2027.
- (3.7a1) PersistentMapping was inadvertently pickling volatile attributes
(http://www.zope.org/Collectors/Zope/2052).
After Commit hooks
------------------
......
......@@ -98,8 +98,8 @@ class PersistentMapping(UserDict, persistent.Persistent):
# actual internal dictionary using the name _container.
def __getstate__(self):
state = {}
state.update(self.__dict__)
state = dict([x for x in self.__dict__.items()
if not x[0].startswith('_v_')])
state['_container'] = state['data']
del state['data']
return state
......
......@@ -11,11 +11,10 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the list interface to PersistentList
"""Tests for PersistentList
"""
import unittest
from persistent.list import PersistentList
l0 = []
l1 = [0]
......@@ -23,19 +22,33 @@ l2 = [0, 1]
class TestPList(unittest.TestCase):
def testTheWorld(self):
# Test constructors
u = PersistentList()
u0 = PersistentList(l0)
u1 = PersistentList(l1)
u2 = PersistentList(l2)
def _getTargetClass(self):
from persistent.list import PersistentList
return PersistentList
uu = PersistentList(u)
uu0 = PersistentList(u0)
uu1 = PersistentList(u1)
uu2 = PersistentList(u2)
def test_volatile_attributes_not_persisted(self):
# http://www.zope.org/Collectors/Zope/2052
m = self._getTargetClass()()
m.foo = 'bar'
m._v_baz = 'qux'
state = m.__getstate__()
self.failUnless('foo' in state)
self.failIf('_v_baz' in state)
v = PersistentList(tuple(u))
def testTheWorld(self):
# Test constructors
pl = self._getTargetClass()
u = pl()
u0 = pl(l0)
u1 = pl(l1)
u2 = pl(l2)
uu = pl(u)
uu0 = pl(u0)
uu1 = pl(u1)
uu2 = pl(u2)
v = pl(tuple(u))
class OtherList:
def __init__(self, initlist):
self.__data = initlist
......@@ -43,8 +56,8 @@ class TestPList(unittest.TestCase):
return len(self.__data)
def __getitem__(self, i):
return self.__data[i]
v0 = PersistentList(OtherList(u0))
vv = PersistentList("this is also a sequence")
v0 = pl(OtherList(u0))
vv = pl("this is also a sequence")
# Test __repr__
eq = self.assertEqual
......@@ -160,7 +173,7 @@ class TestPList(unittest.TestCase):
# Test pop
u = PersistentList([0, -1, 1])
u = pl([0, -1, 1])
u.pop()
eq(u, [0, -1], "u == [0, -1]")
u.pop(0)
......@@ -200,7 +213,7 @@ class TestPList(unittest.TestCase):
# Test sort
u = PersistentList([1, 0])
u = pl([1, 0])
u.sort()
eq(u, u2, "u == u2")
......
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors.
# Copyright (c) 2006 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
......@@ -11,37 +11,50 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the mapping interface to PersistentMapping
"""Test PersistentMapping
"""
import unittest
from persistent.mapping import PersistentMapping
l0 = {}
l1 = {0:0}
l2 = {0:0, 1:1}
class TestPMapping(unittest.TestCase):
class MappingTests(unittest.TestCase):
def _getTargetClass(self):
from persistent.mapping import PersistentMapping
return PersistentMapping
def test_volatile_attributes_not_persisted(self):
# http://www.zope.org/Collectors/Zope/2052
m = self._getTargetClass()()
m.foo = 'bar'
m._v_baz = 'qux'
state = m.__getstate__()
self.failUnless('foo' in state)
self.failIf('_v_baz' in state)
def testTheWorld(self):
# Test constructors
u = PersistentMapping()
u0 = PersistentMapping(l0)
u1 = PersistentMapping(l1)
u2 = PersistentMapping(l2)
pm = self._getTargetClass()
u = pm()
u0 = pm(l0)
u1 = pm(l1)
u2 = pm(l2)
uu = PersistentMapping(u)
uu0 = PersistentMapping(u0)
uu1 = PersistentMapping(u1)
uu2 = PersistentMapping(u2)
uu = pm(u)
uu0 = pm(u0)
uu1 = pm(u1)
uu2 = pm(u2)
class OtherMapping:
def __init__(self, initmapping):
self.__data = initmapping
def items(self):
return self.__data.items()
v0 = PersistentMapping(OtherMapping(u0))
vv = PersistentMapping([(0, 0), (1, 1)])
v0 = pm(OtherMapping(u0))
vv = pm([(0, 0), (1, 1)])
# Test __repr__
eq = self.assertEqual
......@@ -105,7 +118,7 @@ class TestPMapping(unittest.TestCase):
# Test update
l = {"a":"b"}
u = PersistentMapping(l)
u = pm(l)
u.update(u2)
for i in u:
self.failUnless(i in l or i in u2, "i in l or i in u2")
......@@ -151,10 +164,8 @@ class TestPMapping(unittest.TestCase):
u2.clear()
eq(u2, {}, "u2 == {}")
def test_suite():
return unittest.makeSuite(TestPMapping)
return unittest.makeSuite(MappingTests)
if __name__ == "__main__":
loader = unittest.TestLoader()
unittest.main(testLoader=loader)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment