commit 89d1a6ee3a2eabae1f0d7b6bef524a4d12fd8ea7
parent 086c30b2ae868d335293f8cf69bceaffb0801de3
Author: lash <dev@holbrook.no>
Date: Sun, 6 Feb 2022 08:11:47 +0000
Enable alias with comma-separated values
Diffstat:
4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,3 +1,5 @@
+- 0.0.19:
+ * Enable alias with comma separated values
- 0.0.18
* Eliminate key error when list run on empty valid state
* Add replace content method
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = shep
-version = 0.0.18
+version = 0.0.19
description = Multi-state key stores using bit masks
author = Louis Holbrook
author_email = dev@holbrook.no
diff --git a/shep/state.py b/shep/state.py
@@ -50,7 +50,7 @@ class State:
def __check_valid(self, v):
- v = int(v)
+ v = self.__check_value_typ(v)
if self.__reverse.get(v):
raise StateExists(v)
return v
@@ -59,6 +59,7 @@ class State:
def __check_limit(self, v):
if v > self.__limit:
raise OverflowError(v)
+ return v
def __check_value(self, v):
@@ -67,8 +68,12 @@ class State:
return v
+ def __check_value_typ(self, v):
+ return int(v)
+
+
def __check_value_cursor(self, v):
- v = self.__check_valid(v)
+ v = self.__check_value_typ(v)
if v > 1 << self.__c:
raise StateInvalid(v)
return v
@@ -112,9 +117,12 @@ class State:
self.__set(k, v)
- def alias(self, k, v):
+ def alias(self, k, *args):
k = self.__check_name(k)
- v = self.__check_value_cursor(v)
+ v = 0
+ for a in args:
+ a = self.__check_value_cursor(a)
+ v = self.__check_limit(v | a)
if self.__is_pure(v):
raise ValueError('use add to add pure values')
self.__set(k, v)
diff --git a/tests/test_state.py b/tests/test_state.py
@@ -66,6 +66,14 @@ class TestState(unittest.TestCase):
states = State(3)
with self.assertRaises(ValueError):
states.alias('foo', 1)
+ states.add('foo')
+ states.add('bar')
+ states.alias('baz', states.FOO, states.BAR)
+ self.assertEqual(states.BAZ, 3)
+
+
+ def test_alias_multi(self):
+ states = State(3)
def test_alias_cover(self):