shep

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

commit bddf335a53858254e94e27f1d8d8964440a49361
parent bb87ba1e346829e025f3de304ee3bfd19b5101ea
Author: lash <dev@holbrook.no>
Date:   Tue, 29 Mar 2022 09:24:57 +0000

Rehabilitate broken tests

Diffstat:
Mshep/state.py | 4++--
Mtests/test_state.py | 18++++++++++--------
Mtests/test_store.py | 4++++
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/shep/state.py b/shep/state.py @@ -150,7 +150,7 @@ class State: self.__keys[part].append(item) c <<= 1 self.__keys_reverse[item] = state - if self.__reverse.get(state) == None: + if self.__reverse.get(state) == None and not self.check_alias: s = self.elements(state) self.alias(s, state) @@ -340,7 +340,7 @@ class State: if self.event_callback != None: old_state = self.__keys_reverse.get(key) - self.event_callback(key, 'nonexistent', self.name(state)) + self.event_callback(key, None, self.name(state)) self.__add_state_list(state, key) if contents != None: diff --git a/tests/test_state.py b/tests/test_state.py @@ -17,12 +17,15 @@ class MockCallback: def __init__(self): self.items = {} + self.items_from = {} - def add(self, k, v): + def add(self, k, v_from, v_to): if self.items.get(k) == None: self.items[k] = [] - self.items[k].append(v) + self.items_from[k] = [] + self.items[k].append(v_to) + self.items_from[k].append(v_from) class TestState(unittest.TestCase): @@ -119,7 +122,7 @@ class TestState(unittest.TestCase): states.set('abcd', states.BAR) v = states.state('abcd') s = states.name(v) - self.assertEqual(s, '*FOO,BAR') + self.assertEqual(s, '_FOO_BAR') def test_peek(self): @@ -203,10 +206,10 @@ class TestState(unittest.TestCase): states.change('abcd', states.BAZ, states.XYZZY) events = cb.items['abcd'] self.assertEqual(len(events), 4) - self.assertEqual(events[0], states.NEW) - self.assertEqual(events[1], states.FOO) - self.assertEqual(events[2], states.XYZZY) - self.assertEqual(events[3], states.BAZ) + self.assertEqual(states.from_name(events[0]), states.NEW) + self.assertEqual(states.from_name(events[1]), states.FOO) + self.assertEqual(states.from_name(events[2]), states.XYZZY) + self.assertEqual(states.from_name(events[3]), states.BAZ) def test_dynamic(self): @@ -216,7 +219,6 @@ class TestState(unittest.TestCase): states.alias('baz', states.FOO | states.BAR) - def test_mask(self): states = State(3) states.add('foo') diff --git a/tests/test_store.py b/tests/test_store.py @@ -33,6 +33,10 @@ class MockStore: return self.v[k] + def list(self): + return list(self.v.keys()) + + class TestStateItems(unittest.TestCase): def setUp(self):