commit 16a71fb8f69b90bbe2f16519aa71c283a04a4e36
parent ef90fe7fd1130323df264314ab2d9438520d02c8
Author: lash <dev@holbrook.no>
Date: Mon, 14 Aug 2023 09:37:34 +0100
Fix bug deleting persisted state item when set to same value
Diffstat:
6 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,7 @@
+- 0.3.4
+ * Fix persisted store bug deleting item whose value is same after set()
+- 0.3.3
+ * No change
- 0.3.2
* Remove stray stdout output
- 0.3.1
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = shep
-version = 0.3.2
+version = 0.3.4
description = Multi-state key stores using bit masks
author = Louis Holbrook
author_email = dev@holbrook.no
diff --git a/shep/persist.py b/shep/persist.py
@@ -60,6 +60,8 @@ class PersistedState(State):
See shep.state.State.set
"""
from_state = self.state(key)
+ if from_state & or_state == or_state:
+ return
k_from = self.name(from_state)
to_state = super(PersistedState, self).set(key, or_state)
diff --git a/shep/state.py b/shep/state.py
@@ -12,7 +12,6 @@ from shep.error import (
StateCorruptionError,
)
-
re_name = r'^[a-zA-Z_\.]+$'
def join_elements(states):
@@ -426,7 +425,6 @@ class State:
self.__contents[key] = contents
self.register_modify(key)
-
return state
diff --git a/tests/test_file.py b/tests/test_file.py
@@ -308,5 +308,15 @@ class TestFileStore(unittest.TestCase):
self.assertEqual(v, 'zzzz')
+ def test_file_set_same(self):
+ self.states.alias('xyzzy', self.states.FOO | self.states.BAR)
+ item = 'abcd'
+ self.states.put(item)
+ self.states.set(item, self.states.BAR)
+ self.states.state(item) == self.states.XYZZY
+ self.states.set(item, self.states.BAR)
+ self.states.state(item) == self.states.XYZZY
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_store.py b/tests/test_store.py
@@ -84,5 +84,14 @@ class TestStateItems(unittest.TestCase):
self.assertIsNone(self.mockstore.v.get(item))
+ def test_persist_set_same(self):
+ item = b'foo'
+ self.states.put(item)
+ self.states.set(item, self.states.BAR)
+ self.states.state(item) == self.states.PLUGH
+ self.states.set(item, self.states.BAR)
+ self.states.state(item) == self.states.PLUGH
+
+
if __name__ == '__main__':
unittest.main()