Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZEO
Commits
a18f5c42
Commit
a18f5c42
authored
Nov 30, 2001
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add two tests cases the verify the pickles look like old pickles
parent
8e9260c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
src/ZODB/tests/testPersistentMapping.py
src/ZODB/tests/testPersistentMapping.py
+84
-0
No files found.
src/ZODB/tests/testPersistentMapping.py
0 → 100644
View file @
a18f5c42
"""Verify that PersistentMapping works with old versions of Zope.
The comments in PersistentMapping.py address the issue in some detail.
The pickled form of a PersistentMapping must use _container to store
the actual mapping, because old versions of Zope used this attribute.
If the new code doesn't generate pickles that are consistent with the
old code, developers will have a hard time testing the new code.
"""
import
unittest
import
ZODB
from
ZODB.MappingStorage
import
MappingStorage
from
ZODB.Transaction
import
Transaction
import
cPickle
import
cStringIO
import
sys
# This pickle contains a persistent mapping pickle created from the
# old code.
pickle
=
(
'((U
\
x0b
Persistenceq
\
x01
U
\
x11
PersistentMappingtq
\
x02
Nt.}q
\
x03
U
\
n
'
'_containerq
\
x04
}q
\
x05
U
\
x07
versionq
\
x06
U
\
x03
oldq
\
x07
ss.
\
n
'
)
class
PMTests
(
unittest
.
TestCase
):
def
checkOldStyleRoot
(
self
):
# insert the pickle in place of the root
s
=
MappingStorage
()
t
=
Transaction
()
s
.
tpc_begin
(
t
)
s
.
store
(
'
\
000
'
*
8
,
None
,
pickle
,
''
,
t
)
s
.
tpc_vote
(
t
)
s
.
tpc_finish
(
t
)
db
=
ZODB
.
DB
(
s
)
# If the root can be loaded successfully, we should be okay.
r
=
db
.
open
().
root
()
# But make sure it looks like a new mapping
self
.
assert_
(
hasattr
(
r
,
'data'
))
self
.
assert_
(
not
hasattr
(
r
,
'_container'
))
def
checkNewPicklesAreSafe
(
self
):
s
=
MappingStorage
()
db
=
ZODB
.
DB
(
s
)
r
=
db
.
open
().
root
()
r
[
1
]
=
1
r
[
2
]
=
2
## r[3] = r
get_transaction
().
commit
()
# MappingStorage stores serialno + pickle in its _index.
root_pickle
=
s
.
_index
[
'
\
000
'
*
8
][
8
:]
f
=
cStringIO
.
StringIO
(
root_pickle
)
u
=
cPickle
.
Unpickler
(
f
)
klass_info
=
u
.
load
()
klass
=
find_global
(
*
klass_info
[
0
])
inst
=
klass
()
state
=
u
.
load
()
inst
.
__setstate__
(
state
)
self
.
assert_
(
hasattr
(
inst
,
'_container'
))
self
.
assert_
(
not
hasattr
(
inst
,
'data'
))
def
find_global
(
modulename
,
classname
):
"""Helper for this test suite to get special PersistentMapping"""
print
modulename
,
classname
if
classname
==
"PersistentMapping"
:
class
PersistentMapping
:
def
__setstate__
(
self
,
state
):
self
.
__dict__
.
update
(
state
)
return
PersistentMapping
else
:
__import__
(
modulename
)
mod
=
sys
.
modules
[
modulename
]
return
getattr
(
mod
,
classname
)
def
test_suite
():
return
unittest
.
makeSuite
(
PMTests
,
'check'
)
if
__name__
==
"__main__"
:
loader
=
unittest
.
TestLoader
()
loader
.
testMethodPrefix
=
"check"
unittest
.
main
(
testLoader
=
loader
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment