Add full attribute listing

This commit is contained in:
lash 2022-01-31 09:12:49 +00:00
parent 78a3df73bb
commit 6768bd326d
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 58 additions and 9 deletions

View File

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

33
tests/test_report.py Normal file
View File

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

View File

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