shep

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

commit d2bca5134248f49c2935bfda5390b44da69e0250
parent 508ae2397f781968cd11b1cf2f48887c6bec01b3
Author: lash <dev@holbrook.no>
Date:   Mon, 31 Jan 2022 10:06:20 +0000

Return match as separate complex and simple value array

Diffstat:
MCHANGELOG | 2++
Msetup.cfg | 2+-
Mshep/state.py | 10+++++-----
Mtests/test_report.py | 12+++++++-----
4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.3 + * Split match to 2-element tuple, returning complex value and simple values separately - 0.0.2 * Fix rename module name errors * Add listing and matcher diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = shep -version = 0.0.2 +version = 0.0.3 description = Multi-state key value stores using bitmaskings author = Louis Holbrook author_email = dev@holbrook.no diff --git a/shep/state.py b/shep/state.py @@ -95,11 +95,11 @@ class State: def match(self, v, pure=False): - r = [] + alias = None if not pure: - m = self.__reverse.get(v) - if m != None: - r.append(m) + alias = self.__reverse.get(v) + + r = [] c = 1 for i in range(self.__bits): if v & c > 0: @@ -110,4 +110,4 @@ class State: pass c <<= 1 - return r + return (alias, r,) diff --git a/tests/test_report.py b/tests/test_report.py @@ -37,17 +37,19 @@ class TestStateReport(unittest.TestCase): def test_match_alias(self): self.states.alias('xyzzy', self.states.FOO | self.states.BAZ) r = self.states.match(self.states.XYZZY) - for k in ['FOO', 'BAZ', 'XYZZY']: - self.assertIn(k, r) - self.assertNotIn('BAR', r) + for k in ['FOO', 'BAZ']: + self.assertIn(k, r[1]) + self.assertNotIn('BAR', r[1]) + self.assertEqual('XYZZY', r[0]) def test_match_alias_pure(self): self.states.alias('xyzzy', self.states.FOO | self.states.BAZ) r = self.states.match(self.states.XYZZY, pure=True) for k in ['FOO', 'BAZ']: - self.assertIn(k, r) - self.assertNotIn('XYZZY', r) + self.assertIn(k, r[1]) + self.assertNotIn('XYZZY', r[1]) + self.assertIsNone(r[0]) if __name__ == '__main__':