Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
persistent
Commits
8581c0de
Commit
8581c0de
authored
Jun 28, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert another doctest.
parent
69b5b252
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
58 deletions
+44
-58
persistent/tests/test_mapping.py
persistent/tests/test_mapping.py
+44
-58
No files found.
persistent/tests/test_mapping.py
View file @
8581c0de
...
@@ -54,9 +54,12 @@ class PersistentMappingTests(unittest.TestCase):
...
@@ -54,9 +54,12 @@ class PersistentMappingTests(unittest.TestCase):
from
persistent.mapping
import
PersistentMapping
from
persistent.mapping
import
PersistentMapping
return
PersistentMapping
return
PersistentMapping
def
_makeOne
(
self
,
*
args
,
**
kw
):
return
self
.
_getTargetClass
()(
*
args
,
**
kw
)
def
test_volatile_attributes_not_persisted
(
self
):
def
test_volatile_attributes_not_persisted
(
self
):
# http://www.zope.org/Collectors/Zope/2052
# http://www.zope.org/Collectors/Zope/2052
m
=
self
.
_
getTargetClass
()
()
m
=
self
.
_
makeOne
()
m
.
foo
=
'bar'
m
.
foo
=
'bar'
m
.
_v_baz
=
'qux'
m
.
_v_baz
=
'qux'
state
=
m
.
__getstate__
()
state
=
m
.
__getstate__
()
...
@@ -68,24 +71,23 @@ class PersistentMappingTests(unittest.TestCase):
...
@@ -68,24 +71,23 @@ class PersistentMappingTests(unittest.TestCase):
l0
=
{}
l0
=
{}
l1
=
{
0
:
0
}
l1
=
{
0
:
0
}
l2
=
{
0
:
0
,
1
:
1
}
l2
=
{
0
:
0
,
1
:
1
}
pm
=
self
.
_getTargetClass
()
u
=
self
.
_makeOne
()
u
=
pm
()
u0
=
self
.
_makeOne
(
l0
)
u0
=
pm
(
l0
)
u1
=
self
.
_makeOne
(
l1
)
u1
=
pm
(
l1
)
u2
=
self
.
_makeOne
(
l2
)
u2
=
pm
(
l2
)
uu
=
pm
(
u
)
uu
=
self
.
_makeOne
(
u
)
uu0
=
pm
(
u0
)
uu0
=
self
.
_makeOne
(
u0
)
uu1
=
pm
(
u1
)
uu1
=
self
.
_makeOne
(
u1
)
uu2
=
pm
(
u2
)
uu2
=
self
.
_makeOne
(
u2
)
class
OtherMapping
:
class
OtherMapping
:
def
__init__
(
self
,
initmapping
):
def
__init__
(
self
,
initmapping
):
self
.
__data
=
initmapping
self
.
__data
=
initmapping
def
items
(
self
):
def
items
(
self
):
return
self
.
__data
.
items
()
return
self
.
__data
.
items
()
v0
=
pm
(
OtherMapping
(
u0
))
v0
=
self
.
_makeOne
(
OtherMapping
(
u0
))
vv
=
pm
([(
0
,
0
),
(
1
,
1
)])
vv
=
self
.
_makeOne
([(
0
,
0
),
(
1
,
1
)])
# Test __repr__
# Test __repr__
eq
=
self
.
assertEqual
eq
=
self
.
assertEqual
...
@@ -149,7 +151,7 @@ class PersistentMappingTests(unittest.TestCase):
...
@@ -149,7 +151,7 @@ class PersistentMappingTests(unittest.TestCase):
# Test update
# Test update
l
=
{
"a"
:
"b"
}
l
=
{
"a"
:
"b"
}
u
=
pm
(
l
)
u
=
self
.
_makeOne
(
l
)
u
.
update
(
u2
)
u
.
update
(
u2
)
for
i
in
u
:
for
i
in
u
:
self
.
failUnless
(
i
in
l
or
i
in
u2
,
"i in l or i in u2"
)
self
.
failUnless
(
i
in
l
or
i
in
u2
,
"i in l or i in u2"
)
...
@@ -195,56 +197,40 @@ class PersistentMappingTests(unittest.TestCase):
...
@@ -195,56 +197,40 @@ class PersistentMappingTests(unittest.TestCase):
u2
.
clear
()
u2
.
clear
()
eq
(
u2
,
{},
"u2 == {}"
)
eq
(
u2
,
{},
"u2 == {}"
)
def
test_legacy_data
():
def
test___repr___converts_legacy_container_attr
(
self
):
"""
# In the past, PM used a _container attribute. For some time, the
We've deprecated PersistentDict. If you import
# implementation continued to use a _container attribute in pickles
persistent.dict.PersistentDict, you'll get
# (__get/setstate__) to be compatible with older releases. This isn't
persistent.mapping.PersistentMapping.
# really necessary any more. In fact, releases for which this might
# matter can no longer share databases with current releases. Because
>>> import persistent.dict, persistent.mapping
# releases as recent as 3.9.0b5 still use _container in saved state, we
>>> persistent.dict.PersistentDict is persistent.mapping.PersistentMapping
# need to accept such state, but we stop producing it.
True
pm
=
self
.
_makeOne
()
self
.
assertEqual
(
pm
.
__dict__
,
{
'data'
:
{}})
PersistentMapping uses a data attribute for it's mapping data:
# Make it look like an older instance
pm
.
__dict__
.
clear
()
>>> m = persistent.mapping.PersistentMapping()
pm
.
__dict__
[
'_container'
]
=
{
'a'
:
1
}
>>> m.__dict__
self
.
assertEqual
(
pm
.
__dict__
,
{
'_container'
:
{
'a'
:
1
}})
{'data': {}}
pm
.
_p_changed
=
0
self
.
assertEqual
(
repr
(
pm
),
"{'a': 1}"
)
In the past, it used a _container attribute. For some time, the
self
.
assertEqual
(
pm
.
__dict__
,
{
'data'
:
{
'a'
:
1
}})
implementation continued to use a _container attribute in pickles
self
.
assertEqual
(
pm
.
__getstate__
(),
{
'data'
:
{
'a'
:
1
}})
(__get/setstate__) to be compatible with older releases. This isn't
really necessary any more. In fact, releases for which this might
matter can no longer share databases with current releases. Because
class
Test_legacy_PersistentDict
(
unittest
.
TestCase
):
releases as recent as 3.9.0b5 still use _container in saved state, we
need to accept such state, but we stop producing it.
If we reset it's __dict__ with legacy data:
>>> m.__dict__.clear()
def
_getTargetClass
(
self
):
>>> m.__dict__['_container'] = {'a': 1}
from
persistent.dict
import
PersistentDict
>>> m.__dict__
return
PersistentDict
{'_container': {'a': 1}}
>>> m._p_changed = 0
But when we perform any operations on it, the data will be converted
without marking the object as changed:
>>> m
def
test_PD_is_alias_to_PM
(
self
):
{'a': 1}
from
persistent.mapping
import
PersistentMapping
>>> m.__dict__
self
.
assertTrue
(
self
.
_getTargetClass
()
is
PersistentMapping
)
{'data': {'a': 1}}
>>> m._p_changed
0
>>> m.__getstate__()
{'data': {'a': 1}}
"""
def
test_suite
():
def
test_suite
():
import
doctest
return
unittest
.
TestSuite
((
return
unittest
.
TestSuite
((
doctest
.
DocTestSuite
(),
unittest
.
makeSuite
(
PersistentMappingTests
),
unittest
.
makeSuite
(
Test_default
),
unittest
.
makeSuite
(
Test_default
),
unittest
.
makeSuite
(
PersistentMappingTests
),
unittest
.
makeSuite
(
Test_legacy_PersistentDict
),
))
))
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