shep

Multi-state key stores using bit masks for python3
git clone git://git.defalsify.org/shep.git
Log | Files | Refs | LICENSE

commit 242aa6cf78d39b7d857b75de7eced73ee47e2683
parent 16a71fb8f69b90bbe2f16519aa71c283a04a4e36
Author: lash <dev@holbrook.no>
Date:   Mon, 14 Aug 2023 10:38:40 +0100

Improve set same state tests

Diffstat:
Mshep/state.py | 5++++-
Mtests/test_file.py | 25+++++++++++++++++++++----
Mtests/test_state.py | 17+++++++++++++++++
Mtests/test_store.py | 9+--------
4 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/shep/state.py b/shep/state.py @@ -1,6 +1,8 @@ # standard imports import re import datetime +import logging +logg = logging.getLogger() # local imports from shep.error import ( @@ -481,6 +483,7 @@ class State: self.register_modify(key) + logg.debug('move {} {} {}'.format(key, from_state, to_state)) return to_state @@ -508,7 +511,7 @@ class State: new_state = self.__reverse.get(to_state) if new_state == None and self.check_alias: raise StateInvalid('resulting to state is unknown: {}'.format(to_state)) - + return self.__move(key, current_state, to_state) diff --git a/tests/test_file.py b/tests/test_file.py @@ -308,14 +308,31 @@ class TestFileStore(unittest.TestCase): self.assertEqual(v, 'zzzz') - def test_file_set_same(self): - self.states.alias('xyzzy', self.states.FOO | self.states.BAR) + def test_persist_set_same(self): item = 'abcd' + self.states.alias('xyzzy', self.states.FOO, self.states.BAR) self.states.put(item) + self.states.state(item) + self.states.next(item) self.states.set(item, self.states.BAR) - self.states.state(item) == self.states.XYZZY + self.assertEqual(self.states.state(item), self.states.XYZZY) + self.states.set(item, self.states.BAR) - self.states.state(item) == self.states.XYZZY + self.assertEqual(self.states.state(item), self.states.XYZZY) + + d = tempfile.mkdtemp() + self.factory = SimpleFileStoreFactory(d) + states = PersistedState(self.factory.add, 3, check_alias=False) + item = 'abcd' + states.add('foo') + states.add('bar') + states.add('baz') + states.put(item) + states.state(item) + states.next(item) + states.set(item, self.states.BAR) + self.assertEqual(states.state(item), states.FOO | states.BAR) + self.assertEqual(states.state(item), states._FOO__BAR) if __name__ == '__main__': diff --git a/tests/test_state.py b/tests/test_state.py @@ -363,6 +363,23 @@ class TestState(unittest.TestCase): states.from_elements("_FOO__BAR", create_missing=True) + def test_set_same(self): + states = State(4, check_alias=False) + states.add('one') + states.add('two') + states.add('three') + states.put('foo') + states.next('foo') + self.assertEqual(states.state('foo'), states.ONE) + states.set('foo', states.TWO) + self.assertEqual(states.state('foo'), states.ONE | states.TWO) + self.assertEqual(states.state('foo'), states._ONE__TWO) + + states.alias('onetwo', states.ONE, states.TWO) + states.set('foo', states.TWO) + self.assertEqual(states.state('foo'), states.ONETWO) + self.assertEqual(states.state('foo'), states._ONE__TWO) + if __name__ == '__main__': unittest.main() diff --git a/tests/test_store.py b/tests/test_store.py @@ -11,6 +11,7 @@ from shep.error import ( StateItemNotFound, ) +logging.basicConfig(level=logging.DEBUG) logg = logging.getLogger() @@ -84,14 +85,6 @@ 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()