iter states in states group

This commit is contained in:
Andrey Tikhonov 2021-08-17 23:37:15 +03:00
parent 9451a085d1
commit 31ab2cab5e
2 changed files with 10 additions and 0 deletions

View file

@ -118,6 +118,9 @@ class StatesGroupMeta(type):
def __str__(self) -> str:
return f"<StatesGroup '{self.__full_group_name__}'>"
def __iter__(self):
return iter(self.__all_states__)
class StatesGroup(metaclass=StatesGroupMeta):
@classmethod

View file

@ -150,3 +150,10 @@ class TestStatesGroup:
assert 42 not in MyGroup
assert MyGroup.MyNestedGroup.get_root() is MyGroup
def test_iterable(self):
class Group(StatesGroup):
x = State()
y = State()
assert set(Group) == {Group.x, Group.y}