Add full attribute listing
This commit is contained in:
parent
78a3df73bb
commit
6768bd326d
@ -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
33
tests/test_report.py
Normal 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()
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user