Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staticf0x committed Oct 11, 2023
1 parent 788348c commit c05773a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from pylsp import _utils
from pylsp.python_lsp import PythonLSPServer, start_io_lang_server

from docstring_to_markdown import UnknownFormatError


def start(obj):
obj.start()
Expand Down Expand Up @@ -154,3 +156,53 @@ def test_clip_column():
assert _utils.clip_column(2, ["123\n", "123"], 0) == 2
assert _utils.clip_column(3, ["123\n", "123"], 0) == 3
assert _utils.clip_column(4, ["123\n", "123"], 1) == 3


@mock.patch("docstring_to_markdown.convert")
def test_format_docstring_valid_rst_signature(mock_convert):
"""Test that a valid RST docstring includes the function signature."""
docstring = """A function docstring.
Parameters
----------
a : str, something
"""

# Mock the return value to avoid depedency on the real thing
mock_convert.return_value = """A function docstring.
#### Parameters
- `a`: str, something
"""

markdown = _utils.format_docstring(
docstring,
"markdown",
["something(a: str) -> str"],
)["value"]

assert markdown.startswith(
_utils.wrap_signature("something(a: str) -> str"),
)


@mock.patch("docstring_to_markdown.convert", side_effect=UnknownFormatError)
def test_format_docstring_invalid_rst_signature(mock_convert):
"""Test that an invalid RST docstring includes the function signature."""
docstring = """A function docstring.
Parameters
----------
a : str, something
"""

markdown = _utils.format_docstring(
docstring,
"markdown",
["something(a: str) -> str"],
)["value"]

assert markdown.startswith(
_utils.wrap_signature("something(a: str) -> str"),
)

0 comments on commit c05773a

Please sign in to comment.