shep

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

commit 6768bd326d156db90b6c8b4a52b842a500ae7432
parent 78a3df73bbf175805d950bd28a455c9e4085a82b
Author: lash <dev@holbrook.no>
Date:   Mon, 31 Jan 2022 09:12:49 +0000

Add full attribute listing

Diffstat:
Mschiz/state.py | 20++++++++++++--------
Atests/test_report.py | 33+++++++++++++++++++++++++++++++++
Mtests/test_state.py | 14+++++++++++++-
3 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/schiz/state.py b/schiz/state.py @@ -33,6 +33,8 @@ class State: def __check_name(self, k): + if not k.isalpha(): + raise ValueError('only alpha') k = k.upper() try: getattr(self, k) @@ -88,11 +90,13 @@ class State: self.__set(k, v) -# def all(self): -# l = [] -# for k in dir(self): -# if k[0] == '_': -# continue -# if k.upper() != k: -# continue -# l.append(k) + def all(self): + l = [] + for k in dir(self): + if k[0] == '_': + continue + if k.upper() != k: + continue + l.append(k) + l.sort() + return l diff --git a/tests/test_report.py b/tests/test_report.py @@ -0,0 +1,33 @@ +# standard imports +import unittest + +# local imports +from schiz import State +from schiz.error import ( + StateExists, + StateInvalid, + ) + + +class TestStateReport(unittest.TestCase): + + def setUp(self): + self.states = State(4) + self.states.add('foo') + self.states.add('bar') + self.states.add('baz') + + + def test_list_pure(self): + for k in ['FOO', 'BAR', 'BAZ']: + getattr(self.states, k) + + + def test_list_alias(self): + self.states.alias('xyzzy', self.states.FOO | self.states.BAZ) + for k in ['FOO', 'BAR', 'BAZ', 'XYZZY']: + getattr(self.states, k) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_state.py b/tests/test_state.py @@ -11,6 +11,19 @@ from schiz.error import ( class TestState(unittest.TestCase): + def test_key_check(self): + states = State(3) + states.add('foo') + + for k in [ + 'f0o', + 'f oo', + 'f_oo', + ]: + with self.assertRaises(ValueError): + states.add(k) + + def test_get(self): states = State(3) states.add('foo') @@ -63,6 +76,5 @@ class TestState(unittest.TestCase): states.alias('baz', 5) - if __name__ == '__main__': unittest.main()