Commit eee0f323 authored by Jason Madden's avatar Jason Madden

100% coverage for list.py

Remove the old workaround for a broken __cmp__.
parent e3dbb77b
......@@ -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))
......@@ -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__)
......
......@@ -36,7 +36,6 @@ deps =
{[testenv]deps}
coverage
setenv =
PURE_PYTHON = 1
USING_CFFI = 1
[testenv:docs]
......
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