Enable alias with comma-separated values

This commit is contained in:
lash 2022-02-06 08:11:47 +00:00
parent 086c30b2ae
commit 89d1a6ee3a
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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):