mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-10 19:56:45 +03:00
chore: Make Graphene enums iterable like Python enums (#1473)
* Makes Graphene enums iterable like Python enums by implementing __iter__
This commit is contained in:
parent
f891a3683d
commit
0b1bfbf65b
|
@ -56,6 +56,9 @@ class EnumMeta(SubclassWithMeta_Meta):
|
|||
return super(EnumMeta, cls).__call__(*args, **kwargs)
|
||||
# return cls._meta.enum(*args, **kwargs)
|
||||
|
||||
def __iter__(cls):
|
||||
return cls._meta.enum.__iter__()
|
||||
|
||||
def from_enum(
|
||||
cls, enum, name=None, description=None, deprecation_reason=None
|
||||
): # noqa: N805
|
||||
|
|
|
@ -543,3 +543,25 @@ def test_hashable_instance_creation_enum():
|
|||
assert trilogy_map[Episode.NEWHOPE] == "better"
|
||||
assert trilogy_map[Episode.EMPIRE] == "best"
|
||||
assert trilogy_map[5] == "foo"
|
||||
|
||||
|
||||
def test_enum_iteration():
|
||||
class TestEnum(Enum):
|
||||
FIRST = 1
|
||||
SECOND = 2
|
||||
|
||||
result = []
|
||||
expected_values = ["FIRST", "SECOND"]
|
||||
for c in TestEnum:
|
||||
result.append(c.name)
|
||||
assert result == expected_values
|
||||
|
||||
|
||||
def test_iterable_instance_creation_enum():
|
||||
TestEnum = Enum("TestEnum", [("FIRST", 1), ("SECOND", 2)])
|
||||
|
||||
result = []
|
||||
expected_values = ["FIRST", "SECOND"]
|
||||
for c in TestEnum:
|
||||
result.append(c.name)
|
||||
assert result == expected_values
|
||||
|
|
Loading…
Reference in New Issue
Block a user