[Checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/ Semantics of '_p_deactivate()' identical to assigning None to '_p_changed'.

Tres Seaver tseaver at palladion.com
Tue Feb 15 12:37:08 EST 2011


Log message for revision 120349:
  Semantics of '_p_deactivate()' identical to assigning None to '_p_changed'.
  

Changed:
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py

-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py	2011-02-15 17:37:06 UTC (rev 120348)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py	2011-02-15 17:37:08 UTC (rev 120349)
@@ -92,8 +92,7 @@
                 self._set_changed_flag(value)
         else:
             if value is None: # -> ghost
-                if not self.__flags & _CHANGED:
-                    self._p_invalidate()
+                self._p_deactivate()
             else:
                 self._set_changed_flag(value)
 
@@ -158,6 +157,8 @@
     def _p_deactivate(self):
         """ See IPersistent.
         """
+        if self.__flags is not None and not self.__flags & _CHANGED:
+            self._p_invalidate()
 
     def _p_invalidate(self):
         """ See IPersistent.

Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py	2011-02-15 17:37:06 UTC (rev 120348)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/tests/test_pypersistent.py	2011-02-15 17:37:08 UTC (rev 120349)
@@ -391,3 +391,94 @@
         inst._p_changed = True
         inst._p_activate() # noop from 'saved' state
         self.assertEqual(inst._p_state, 'unsaved')
+
+    def test__p_deactivate_from_new(self):
+        inst = self._makeOne()
+        inst._p_deactivate()
+        self.assertEqual(inst._p_state, 'new')
+
+    def test__p_deactivate_from_unsaved(self):
+        inst = self._makeOne()
+        inst._p_changed = True
+        inst._p_deactivate()
+        # can't transition 'unsaved' -> 'new'
+        self.assertEqual(inst._p_state, 'unsaved')
+
+    def test__p_deactivate_from_ghost(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_deactivate()
+        self.assertEqual(inst._p_state, 'ghost')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_deactivate_from_saved(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_activate()
+        jar._loaded = []
+        inst._p_deactivate()
+        self.assertEqual(inst._p_state, 'ghost')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_deactivate_from_changed(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_activate()
+        inst._p_changed = True
+        jar._loaded = []
+        jar._registered = []
+        inst._p_deactivate()
+        # assigning None is ignored when dirty
+        self.assertEqual(inst._p_state, 'changed')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_deactivate_when_sticky(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_changed = False
+        inst._p_sticky = True
+        self.assertRaises(ValueError, inst._p_deactivate)
+
+    def test__p_invalidate_from_new(self):
+        inst = self._makeOne()
+        inst._p_invalidate()
+        self.assertEqual(inst._p_state, 'new')
+
+    def test__p_invalidate_from_unsaved(self):
+        inst = self._makeOne()
+        inst._p_changed = True
+        inst._p_invalidate()
+        self.assertEqual(inst._p_state, 'new')
+
+    def test__p_invalidate_from_ghost(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_invalidate()
+        self.assertEqual(inst._p_state, 'ghost')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_invalidate_from_saved(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_activate()
+        jar._loaded = []
+        jar._registered = []
+        inst._p_invalidate()
+        self.assertEqual(inst._p_state, 'ghost')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_invalidate_from_changed(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_activate()
+        inst._p_changed = True
+        jar._loaded = []
+        jar._registered = []
+        inst._p_invalidate()
+        self.assertEqual(inst._p_state, 'ghost')
+        self.assertEqual(list(jar._loaded), [])
+        self.assertEqual(list(jar._registered), [])
+
+    def test__p_invalidate_when_sticky(self):
+        inst, jar, OID = self._makeOneWithJar()
+        inst._p_changed = False
+        inst._p_sticky = True
+        self.assertRaises(ValueError, inst._p_invalidate)



More information about the checkins mailing list