Skip to content

Commit

Permalink
chore: default enum description to "An enumeration." (#1502)
Browse files Browse the repository at this point in the history
* Default enum description to "An enumeration."

default to this string, which is used in many tests, is causing

* Use the docstring descriptions of enums when they are present

* Added tests

* chore: add missing newline

* Fix new line

---------

Co-authored-by: Erik Wrede <erikwrede@users.noreply.github.com>
  • Loading branch information
firaskafri and erikwrede authored May 25, 2023
1 parent 57cbef6 commit 8ede21e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphene/types/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def from_enum(
cls, enum, name=None, description=None, deprecation_reason=None
): # noqa: N805
name = name or enum.__name__
description = description or enum.__doc__
description = description or enum.__doc__ or "An enumeration."
meta_dict = {
"enum": enum,
"description": description,
Expand Down
15 changes: 15 additions & 0 deletions graphene/types/tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def test_enum_from_builtin_enum():
assert RGB.BLUE


def test_enum_custom_description_in_constructor():
description = "An enumeration, but with a custom description"
RGB = Enum(
"RGB",
"RED,GREEN,BLUE",
description=description,
)
assert RGB._meta.description == description


def test_enum_from_python3_enum_uses_default_builtin_doc():
RGB = Enum("RGB", "RED,GREEN,BLUE")
assert RGB._meta.description == "An enumeration."


def test_enum_from_builtin_enum_accepts_lambda_description():
def custom_description(value):
if not value:
Expand Down

0 comments on commit 8ede21e

Please sign in to comment.