Dynamic state
This commit is contained in:
parent
798262f00f
commit
57a9ea44ff
@ -2,6 +2,7 @@
|
||||
* Optional, pluggable verifier to protect state transition
|
||||
* Change method for atomic simultaneous set and unset
|
||||
* Optionally allow undefined composite states
|
||||
* Dynamic bits
|
||||
- 0.1.0
|
||||
* Release version bump
|
||||
- 0.0.19:
|
||||
|
@ -31,6 +31,7 @@ class State:
|
||||
base_state_name = 'NEW'
|
||||
|
||||
def __init__(self, bits, logger=None, verifier=None, check_alias=True, event_callback=None):
|
||||
self.__initial_bits = bits
|
||||
self.__bits = bits
|
||||
self.__limit = (1 << bits) - 1
|
||||
self.__c = 0
|
||||
@ -92,6 +93,9 @@ class State:
|
||||
|
||||
# enforces state value within bit limit of instantiation
|
||||
def __check_limit(self, v):
|
||||
if self.__initial_bits == 0:
|
||||
self.__bits += 1
|
||||
self.__limit = (1 << self.__bits) - 1
|
||||
if v > self.__limit:
|
||||
raise OverflowError(v)
|
||||
return v
|
||||
|
@ -208,5 +208,12 @@ class TestState(unittest.TestCase):
|
||||
self.assertEqual(events[3], states.BAZ)
|
||||
|
||||
|
||||
def test_dynamic(self):
|
||||
states = State(0)
|
||||
states.add('foo')
|
||||
states.add('bar')
|
||||
states.alias('baz', states.FOO | states.BAR)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user