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
6568869c
Commit
6568869c
authored
Dec 16, 2014
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
persistent.picklecache: 100% branch coverage.
parent
1462ee2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
1 deletion
+59
-1
persistent/picklecache.py
persistent/picklecache.py
+3
-1
persistent/tests/test_picklecache.py
persistent/tests/test_picklecache.py
+56
-0
No files found.
persistent/picklecache.py
View file @
6568869c
...
...
@@ -253,7 +253,9 @@ class PickleCache(object):
if
value
is
not
None
and
value
.
_p_state
!=
GHOST
:
value
.
_p_invalidate
()
node
=
self
.
ring
.
next
while
node
is
not
self
.
ring
:
while
True
:
if
node
is
self
.
ring
:
break
# pragma: no cover belt-and-suspenders
if
node
.
object
is
value
:
node
.
prev
.
next
,
node
.
next
.
prev
=
node
.
next
,
node
.
prev
break
...
...
persistent/tests/test_picklecache.py
View file @
6568869c
...
...
@@ -89,6 +89,14 @@ class PickleCacheTests(unittest.TestCase):
else
:
self
.
fail
(
"Didn't raise ValueError with non-string OID."
)
def
test___setitem___duplicate_oid_same_obj
(
self
):
from
persistent._compat
import
_b
KEY
=
_b
(
'original'
)
cache
=
self
.
_makeOne
()
original
=
self
.
_makePersist
()
cache
[
KEY
]
=
original
cache
[
KEY
]
=
original
def
test___setitem___duplicate_oid_raises_KeyError
(
self
):
from
persistent._compat
import
_b
KEY
=
_b
(
'original'
)
...
...
@@ -448,6 +456,54 @@ class PickleCacheTests(unittest.TestCase):
for
oid
in
oids
:
self
.
assertTrue
(
cache
.
get
(
oid
)
is
None
)
def
test_full_sweep_w_sticky
(
self
):
import
gc
from
persistent.interfaces
import
UPTODATE
from
persistent.interfaces
import
STICKY
from
persistent._compat
import
_b
cache
=
self
.
_makeOne
()
oids
=
[]
for
i
in
range
(
100
):
oid
=
_b
(
'oid_%04d'
%
i
)
oids
.
append
(
oid
)
state
=
UPTODATE
if
i
>
0
else
STICKY
cache
[
oid
]
=
self
.
_makePersist
(
oid
=
oid
,
state
=
state
)
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
100
)
cache
.
full_sweep
()
gc
.
collect
()
# banish the ghosts who are no longer in the ring
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
1
)
self
.
assertTrue
(
cache
.
ring
.
next
is
not
cache
.
ring
)
self
.
assertTrue
(
cache
.
get
(
oids
[
0
])
is
not
None
)
for
oid
in
oids
[
1
:]:
self
.
assertTrue
(
cache
.
get
(
oid
)
is
None
)
def
test_full_sweep_w_changed
(
self
):
import
gc
from
persistent.interfaces
import
UPTODATE
from
persistent.interfaces
import
CHANGED
from
persistent._compat
import
_b
cache
=
self
.
_makeOne
()
oids
=
[]
for
i
in
range
(
100
):
oid
=
_b
(
'oid_%04d'
%
i
)
oids
.
append
(
oid
)
state
=
UPTODATE
if
i
>
0
else
CHANGED
cache
[
oid
]
=
self
.
_makePersist
(
oid
=
oid
,
state
=
state
)
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
100
)
cache
.
full_sweep
()
gc
.
collect
()
# banish the ghosts who are no longer in the ring
self
.
assertEqual
(
cache
.
cache_non_ghost_count
,
1
)
self
.
assertTrue
(
cache
.
ring
.
next
is
not
cache
.
ring
)
self
.
assertTrue
(
cache
.
get
(
oids
[
0
])
is
not
None
)
for
oid
in
oids
[
1
:]:
self
.
assertTrue
(
cache
.
get
(
oid
)
is
None
)
def
test_minimize
(
self
):
import
gc
from
persistent.interfaces
import
UPTODATE
...
...
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