Commit d48634de authored by Tres Seaver's avatar Tres Seaver

Coverage.

Drop can't-get-here condition in PickleCache.__delitem__.

Cover PickleCache.debug_info, and fix a bug found thereby.
parent c3173352
......@@ -87,8 +87,6 @@ class PickleCache(object):
else:
value = self.data.pop(oid)
node = self.ring.next
if node is None:
return
while node is not self.ring:
if node.object is value:
node.prev.next, node.next.prev = node.next, node.prev
......@@ -215,13 +213,13 @@ class PickleCache(object):
result = []
for oid, klass in self.persistent_classes.items():
result.append((oid,
len(gc.getreferents(klass)),
len(gc.get_referents(klass)),
type(klass).__name__,
klass._p_state,
))
for oid, value in self.data.items():
result.append((oid,
len(gc.getreferents(value)),
len(gc.get_referents(value)),
type(value).__name__,
value._p_state,
))
......@@ -230,7 +228,7 @@ class PickleCache(object):
def update_object_size_estimation(self, oid, new_size):
""" See IPickleCache.
"""
pass
pass #pragma NO COVER
cache_size = property(lambda self: self.target_size)
cache_drain_resistance = property(lambda self: self.drain_resistance)
......
......@@ -168,6 +168,51 @@ class PickleCacheTests(unittest.TestCase):
else:
self.fail("Didn't raise KeyError with nonesuch OID.")
def test___delitem___w_persistent_class(self):
cache = self._makeOne()
class pclass(object):
pass
cache = self._makeOne()
cache['pclass'] = pclass
del cache['pclass']
self.assertTrue(cache.get('pclass', self) is self)
self.assertFalse('pclass' in cache.persistent_classes)
self.assertEqual(cache.ringlen(), 0)
def test___delitem___w_normal_object(self):
from persistent.interfaces import UPTODATE
cache = self._makeOne()
uptodate = self._makePersist(state=UPTODATE)
cache['uptodate'] = uptodate
del cache['uptodate']
self.assertTrue(cache.get('uptodate', self) is self)
def test___delitem___w_ghost(self):
from persistent.interfaces import GHOST
cache = self._makeOne()
ghost = self._makePersist(state=GHOST)
cache['ghost'] = ghost
del cache['ghost']
self.assertTrue(cache.get('ghost', self) is self)
def test___delitem___w_remaining_object(self):
from persistent.interfaces import UPTODATE
cache = self._makeOne()
remains = self._makePersist(state=UPTODATE)
uptodate = self._makePersist(state=UPTODATE)
cache['remains'] = remains
cache['uptodate'] = uptodate
del cache['uptodate']
self.assertTrue(cache.get('uptodate', self) is self)
self.assertTrue(cache.get('remains', self) is remains)
def test_lruitems(self):
from persistent.interfaces import UPTODATE
cache = self._makeOne()
......@@ -543,6 +588,57 @@ class PickleCacheTests(unittest.TestCase):
cache.invalidate('123')
self.failIf('123' in cache.persistent_classes)
def test_debug_info_w_persistent_class(self):
import gc
from persistent.interfaces import UPTODATE
class pclass(object):
pass
cache = self._makeOne()
pclass._p_state = UPTODATE
cache['pclass'] = pclass
info = cache.debug_info()
self.assertEqual(len(info), 1)
oid, refc, typ, state = info[0]
self.assertEqual(oid, 'pclass')
self.assertEqual(refc, len(gc.get_referents(pclass)))
self.assertEqual(typ, 'type')
self.assertEqual(state, UPTODATE)
def test_debug_info_w_normal_object(self):
import gc
from persistent.interfaces import UPTODATE
cache = self._makeOne()
uptodate = self._makePersist(state=UPTODATE)
cache['uptodate'] = uptodate
info = cache.debug_info()
self.assertEqual(len(info), 1)
oid, refc, typ, state = info[0]
self.assertEqual(oid, 'uptodate')
self.assertEqual(refc, len(gc.get_referents(uptodate)))
self.assertEqual(typ, 'DummyPersistent')
self.assertEqual(state, UPTODATE)
def test_debug_info_w_ghost(self):
import gc
from persistent.interfaces import GHOST
cache = self._makeOne()
ghost = self._makePersist(state=GHOST)
cache['ghost'] = ghost
info = cache.debug_info()
self.assertEqual(len(info), 1)
oid, refc, typ, state = info[0]
self.assertEqual(oid, 'ghost')
self.assertEqual(refc, len(gc.get_referents(ghost)))
self.assertEqual(typ, 'DummyPersistent')
self.assertEqual(state, GHOST)
class DummyPersistent(object):
......
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