mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 19:32:33 +03:00
black
This commit is contained in:
parent
9f3d386b89
commit
c36bcb35bb
|
@ -10,8 +10,10 @@ class Episode(Enum):
|
||||||
EMPIRE = 5
|
EMPIRE = 5
|
||||||
JEDI = 6
|
JEDI = 6
|
||||||
|
|
||||||
|
|
||||||
GrapheneEpisode = graphene.Enum.from_enum(Episode, legacy_enum_resolver=False)
|
GrapheneEpisode = graphene.Enum.from_enum(Episode, legacy_enum_resolver=False)
|
||||||
|
|
||||||
|
|
||||||
class Character(graphene.Interface):
|
class Character(graphene.Interface):
|
||||||
id = graphene.ID()
|
id = graphene.ID()
|
||||||
name = graphene.String()
|
name = graphene.String()
|
||||||
|
|
|
@ -65,7 +65,9 @@ class EnumMeta(SubclassWithMeta_Meta):
|
||||||
return cls.from_enum(PyEnum(*args, **kwargs), description=description)
|
return cls.from_enum(PyEnum(*args, **kwargs), description=description)
|
||||||
return super(EnumMeta, cls).__call__(*args, **kwargs)
|
return super(EnumMeta, cls).__call__(*args, **kwargs)
|
||||||
|
|
||||||
def from_enum(cls, enum, description=None, deprecation_reason=None, legacy_enum_resolver=True): # noqa: N805
|
def from_enum(
|
||||||
|
cls, enum, description=None, deprecation_reason=None, legacy_enum_resolver=True
|
||||||
|
): # noqa: N805
|
||||||
description = description or enum.__doc__
|
description = description or enum.__doc__
|
||||||
meta_dict = {
|
meta_dict = {
|
||||||
"enum": enum,
|
"enum": enum,
|
||||||
|
|
|
@ -182,6 +182,7 @@ def test_enum_value_as_unmounted_argument():
|
||||||
assert isinstance(unmounted_field, Argument)
|
assert isinstance(unmounted_field, Argument)
|
||||||
assert unmounted_field.type == RGB
|
assert unmounted_field.type == RGB
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_enum_can_be_compared():
|
def test_legacy_enum_can_be_compared():
|
||||||
class RGB(Enum):
|
class RGB(Enum):
|
||||||
RED = 1
|
RED = 1
|
||||||
|
@ -192,11 +193,13 @@ def test_legacy_enum_can_be_compared():
|
||||||
assert RGB.GREEN == 2
|
assert RGB.GREEN == 2
|
||||||
assert RGB.BLUE == 3
|
assert RGB.BLUE == 3
|
||||||
|
|
||||||
|
|
||||||
def test_new_enum_only_compare_to_enum_instances():
|
def test_new_enum_only_compare_to_enum_instances():
|
||||||
class RGBBase(PyEnum):
|
class RGBBase(PyEnum):
|
||||||
RED = 1
|
RED = 1
|
||||||
GREEN = 2
|
GREEN = 2
|
||||||
BLUE = 3
|
BLUE = 3
|
||||||
|
|
||||||
RGB = Enum.from_enum(RGBBase, legacy_enum_resolver=False)
|
RGB = Enum.from_enum(RGBBase, legacy_enum_resolver=False)
|
||||||
|
|
||||||
assert RGB.RED == RGBBase.RED
|
assert RGB.RED == RGBBase.RED
|
||||||
|
@ -206,6 +209,7 @@ def test_new_enum_only_compare_to_enum_instances():
|
||||||
assert RGB.GREEN != 2
|
assert RGB.GREEN != 2
|
||||||
assert RGB.BLUE != 3
|
assert RGB.BLUE != 3
|
||||||
|
|
||||||
|
|
||||||
def test_enum_can_be_initialzied():
|
def test_enum_can_be_initialzied():
|
||||||
class RGB(Enum):
|
class RGB(Enum):
|
||||||
RED = 1
|
RED = 1
|
||||||
|
|
|
@ -43,7 +43,6 @@ def _call_and_get_arg(mocker, resolver_name, query):
|
||||||
return resolver.call_args[1]["v"]
|
return resolver.call_args[1]["v"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_enum_python(mocker):
|
def test_resolve_enum_python(mocker):
|
||||||
arg = _call_and_get_arg(mocker, "resolve_python", "{python(v:P2)}")
|
arg = _call_and_get_arg(mocker, "resolve_python", "{python(v:P2)}")
|
||||||
assert arg is PythonBaseEnum.P2
|
assert arg is PythonBaseEnum.P2
|
||||||
|
|
|
@ -57,6 +57,7 @@ def test_enum_legacy():
|
||||||
GraphQLEnumValue(name="bar", value=2, description="Description bar=2"),
|
GraphQLEnumValue(name="bar", value=2, description="Description bar=2"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_enum_new():
|
def test_enum_new():
|
||||||
class MyEnumBase(PyEnum):
|
class MyEnumBase(PyEnum):
|
||||||
"""Description"""
|
"""Description"""
|
||||||
|
@ -89,7 +90,9 @@ def test_enum_new():
|
||||||
description="Description foo=1",
|
description="Description foo=1",
|
||||||
deprecation_reason="Is deprecated",
|
deprecation_reason="Is deprecated",
|
||||||
),
|
),
|
||||||
GraphQLEnumValue(name="bar", value=MyEnumBase.bar, description="Description bar=2"),
|
GraphQLEnumValue(
|
||||||
|
name="bar", value=MyEnumBase.bar, description="Description bar=2"
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user