Skip to content

Commit

Permalink
add group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eonu committed Dec 26, 2023
1 parent 3f3f77a commit 0fb8b9c
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions tests/unit/test_internal/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class Mode(enum.Enum):
FUNCTION = "function"
COMMAND = "command"
COMMAND_WITH_HELP = "command_with_help"
STRING = "string"


Expand All @@ -24,6 +25,10 @@ def f() -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -37,6 +42,10 @@ def f() -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -53,6 +62,10 @@ def f() -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -69,6 +82,10 @@ def f() -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -90,7 +107,11 @@ def f(*, opt: int) -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
assert f.params[0].help == "An option."
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -114,7 +135,11 @@ def f(*, opt: int) -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
assert f.params[0].help == "An option."
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

Expand All @@ -138,8 +163,115 @@ def f(*, opt: int) -> None:

if mode == Mode.COMMAND:
f = feud.command()(f)
assert f.help == _docstring.get_description(f)
assert f.params[0].help == "An option."
elif mode == Mode.COMMAND_WITH_HELP:
f = feud.command(help="Override.")(f)
assert f.help == "Override."
elif mode == Mode.STRING:
f = f.__doc__

assert _docstring.get_description(f) == "Line 1.\n\nLine 2."


def test_get_description_class_single_line_no_doc() -> None:
class Group(feud.Group):
pass

assert feud.compile(Group).help is None


def test_get_description_class_single_line_doc() -> None:
class Group(feud.Group):
"""Line 1."""

assert feud.compile(Group).help == "Line 1."


def test_get_description_class_single_line_doc_with_examples() -> None:
class Group(feud.Group):
"""Line 1.
Examples
--------
>>> # Hello World!
"""

assert feud.compile(Group).help == "Line 1."


def test_get_description_class_multi_line_doc() -> None:
class Group(feud.Group):
"""Line 1.
Line 2.
"""

assert feud.compile(Group).help == "Line 1.\n\nLine 2."


def test_get_description_class_multi_line_doc_with_examples() -> None:
class Group(feud.Group):
"""Line 1.
Line 2.
Examples
--------
>>> # Hello World!
"""

assert feud.compile(Group).help == "Line 1.\n\nLine 2."


def test_get_description_class_multi_line_doc_with_f() -> None:
class Group(feud.Group):
"""Line 1.
Line 2.\f
"""

assert feud.compile(Group).help == "Line 1.\n\nLine 2."


def test_get_description_class_multi_line_doc_with_examples_and_f() -> None:
class Group(feud.Group):
"""Line 1.
Line 2.\f
Examples
--------
>>> # Hello World!
"""

assert feud.compile(Group).help == "Line 1.\n\nLine 2."


def test_get_description_class_main() -> None:
class Group(feud.Group):
def __main__() -> None:
"""Line 1.
Line 2.\f
Examples
--------
>>> # Hello World!
"""

assert feud.compile(Group).help == "Line 1.\n\nLine 2."


def test_get_description_class_override() -> None:
class Group(feud.Group, help="Override."):
"""Line 1.
Line 2.\f
Examples
--------
>>> # Hello World!
"""

assert feud.compile(Group).help == "Override."

0 comments on commit 0fb8b9c

Please sign in to comment.