Commit e3a9b13a authored by Jason Madden's avatar Jason Madden

100% coverage for persistence.py

parent 9ac215fe
......@@ -381,8 +381,11 @@ class Persistent(object):
# by telling it this object no longer takes any bytes
# (-1 is a magic number to compensate for the implementation,
# which always adds one to the size given)
cache = getattr(self.__jar, '_cache', None)
if cache is not None:
try:
cache = self.__jar._cache
except AttributeError:
pass
else:
cache.update_object_size_estimation(self.__oid,
-1)
# See notes in PickleCache.sweep for why we have to do this
......
......@@ -1437,6 +1437,7 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def _clearMRU(self, jar):
jar._cache._mru[:] = []
def test_accessed_with_jar_and_oid_but_not_in_cache(self):
# This scenario arises in ZODB: ZODB.serialize.ObjectWriter
# can assign a jar and an oid to newly seen persistent objects,
......@@ -1459,6 +1460,37 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
c1._p_accessed()
self._checkMRU(jar, [])
def test_accessed_invalidated_with_jar_and_oid_but_no_cache(self):
# This scenario arises in ZODB tests where the jar is faked
from persistent._compat import _b
KEY = _b('123')
class Jar(object):
accessed = False
def __getattr__(self, name):
if name == '_cache':
self.accessed = True
raise AttributeError(name)
def register(self, *args):
pass
c1 = self._makeOne()
c1._p_oid = KEY
c1._p_jar = Jar()
c1._p_changed = True
self.assertEqual(c1._p_state, 1)
c1._p_accessed()
self.assertTrue(c1._p_jar.accessed)
c1._p_jar.accessed = False
c1._p_invalidate_deactivate_helper()
self.assertTrue(c1._p_jar.accessed)
c1._p_jar.accessed = False
c1._Persistent__flags = None # coverage
c1._p_invalidate_deactivate_helper()
self.assertTrue(c1._p_jar.accessed)
_add_to_suite = [PyPersistentTests]
if not os.environ.get('PURE_PYTHON'):
......
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