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
eee0f323
Commit
eee0f323
authored
Jul 31, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
100% coverage for list.py
Remove the old workaround for a broken __cmp__.
parent
e3dbb77b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
16 deletions
+86
-16
persistent/list.py
persistent/list.py
+10
-15
persistent/tests/test_list.py
persistent/tests/test_list.py
+76
-0
tox.ini
tox.ini
+0
-1
No files found.
persistent/list.py
View file @
eee0f323
...
...
@@ -28,9 +28,6 @@ class PersistentList(UserList, persistent.Persistent):
"""
__super_setitem
=
UserList
.
__setitem__
__super_delitem
=
UserList
.
__delitem__
if
PYTHON2
:
# pragma: no cover
__super_setslice
=
UserList
.
__setslice__
__super_delslice
=
UserList
.
__delslice__
__super_iadd
=
UserList
.
__iadd__
__super_imul
=
UserList
.
__imul__
__super_append
=
UserList
.
append
...
...
@@ -49,13 +46,17 @@ class PersistentList(UserList, persistent.Persistent):
self
.
__super_delitem
(
i
)
self
.
_p_changed
=
1
def
__setslice__
(
self
,
i
,
j
,
other
):
self
.
__super_setslice
(
i
,
j
,
other
)
self
.
_p_changed
=
1
if
PYTHON2
:
# pragma: no cover
__super_setslice
=
UserList
.
__setslice__
__super_delslice
=
UserList
.
__delslice__
def
__delslice__
(
self
,
i
,
j
):
self
.
__super_delslice
(
i
,
j
)
self
.
_p_changed
=
1
def
__setslice__
(
self
,
i
,
j
,
other
):
self
.
__super_setslice
(
i
,
j
,
other
)
self
.
_p_changed
=
1
def
__delslice__
(
self
,
i
,
j
):
self
.
__super_delslice
(
i
,
j
)
self
.
_p_changed
=
1
def
__iadd__
(
self
,
other
):
L
=
self
.
__super_iadd
(
other
)
...
...
@@ -95,9 +96,3 @@ class PersistentList(UserList, persistent.Persistent):
def
extend
(
self
,
other
):
self
.
__super_extend
(
other
)
self
.
_p_changed
=
1
# This works around a bug in Python 2.1.x (up to 2.1.2 at least) where the
# __cmp__ bogusly raises a RuntimeError, and because this is an extension
# class, none of the rich comparison stuff works anyway.
def
__cmp__
(
self
,
other
):
return
cmp
(
self
.
data
,
self
.
_UserList__cast
(
other
))
persistent/tests/test_list.py
View file @
eee0f323
...
...
@@ -20,6 +20,8 @@ l0 = []
l1
=
[
0
]
l2
=
[
0
,
1
]
# pylint:disable=protected-access
class
OtherList
:
def
__init__
(
self
,
initlist
):
self
.
__data
=
initlist
...
...
@@ -34,6 +36,17 @@ class TestPList(unittest.TestCase):
from
persistent.list
import
PersistentList
return
PersistentList
def
_makeJar
(
self
):
class
Jar
(
object
):
def
register
(
self
,
obj
):
"no-op"
return
Jar
()
def
_makeOne
(
self
,
*
args
):
inst
=
self
.
_getTargetClass
()(
*
args
)
inst
.
_p_jar
=
self
.
_makeJar
()
return
inst
def
test_volatile_attributes_not_persisted
(
self
):
# http://www.zope.org/Collectors/Zope/2052
m
=
self
.
_getTargetClass
()()
...
...
@@ -248,6 +261,69 @@ class TestPList(unittest.TestCase):
u
*=
3
eq
(
u
,
u1
+
u1
+
u1
,
"u == u1 + u1 + u1"
)
def
test_setslice
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertFalse
(
inst
.
_p_changed
)
inst
[:]
=
[
1
,
2
,
3
]
self
.
assertEqual
(
inst
,
[
1
,
2
,
3
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_delslice
(
self
):
inst
=
self
.
_makeOne
([
1
,
2
,
3
])
self
.
assertFalse
(
inst
.
_p_changed
)
self
.
assertEqual
(
inst
,
[
1
,
2
,
3
])
del
inst
[:]
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_iadd
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertFalse
(
inst
.
_p_changed
)
inst
+=
[
1
,
2
,
3
]
self
.
assertEqual
(
inst
,
[
1
,
2
,
3
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_extend
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertFalse
(
inst
.
_p_changed
)
inst
.
extend
([
1
,
2
,
3
])
self
.
assertEqual
(
inst
,
[
1
,
2
,
3
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_imul
(
self
):
inst
=
self
.
_makeOne
([
1
])
self
.
assertFalse
(
inst
.
_p_changed
)
inst
*=
2
self
.
assertEqual
(
inst
,
[
1
,
1
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_append
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertFalse
(
inst
.
_p_changed
)
inst
.
append
(
1
)
self
.
assertEqual
(
inst
,
[
1
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_insert
(
self
):
inst
=
self
.
_makeOne
()
self
.
assertFalse
(
inst
.
_p_changed
)
inst
.
insert
(
0
,
1
)
self
.
assertEqual
(
inst
,
[
1
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_remove
(
self
):
inst
=
self
.
_makeOne
([
1
])
self
.
assertFalse
(
inst
.
_p_changed
)
inst
.
remove
(
1
)
self
.
assertEqual
(
inst
,
[])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_reverse
(
self
):
inst
=
self
.
_makeOne
([
2
,
1
])
self
.
assertFalse
(
inst
.
_p_changed
)
inst
.
reverse
()
self
.
assertEqual
(
inst
,
[
1
,
2
])
self
.
assertTrue
(
inst
.
_p_changed
)
def
test_suite
():
return
unittest
.
defaultTestLoader
.
loadTestsFromName
(
__name__
)
...
...
tox.ini
View file @
eee0f323
...
...
@@ -36,7 +36,6 @@ deps =
{
[testenv]
deps}
coverage
setenv
=
PURE_PYTHON
=
1
USING_CFFI
=
1
[testenv:docs]
...
...
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