Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pydocstringformatter/_configuration/toml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ def parse_toml_option(
if value is True:
return [action.option_strings[0]]
return []
if isinstance(action, argparse._StoreAction):
elif isinstance(action, argparse._StoreAction):
if isinstance(value, int):
value = str(value)
return [action.option_strings[0], value]
return [] # pragma: no cover
elif isinstance(action, argparse._ExtendAction):
if isinstance(value, str):
value = str(value)
return [action.option_strings[0], value]
else:
raise NotImplementedError


def parse_toml_file(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ def test_valid_toml_two(
assert not output.err


def test_toml_style(
capsys: pytest.CaptureFixture[str], monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test a correct toml with write = False."""
monkeypatch.chdir(CONFIG_DATA / "valid_toml_two")
pydocstringformatter.run_docstring_formatter(["test_package"])
# I am assuming the default style is "pep257"
default_output = capsys.readouterr()
assert default_output.out.endswith(
'''
@@ -1,3 +1,2 @@
-"""
-A docstring"""
+"""A docstring."""

'''
)

with open("pyproject.toml", "a", encoding="utf8") as file:
file.write("style = 'numpydoc'")

pydocstringformatter.run_docstring_formatter(["test_package"])
numpydoc_output = capsys.readouterr()

assert numpydoc_output.out.endswith(
'''
@@ -1,3 +1,3 @@
+"""A docstring.
"""
-A docstring"""

'''
)
assert not numpydoc_output.err


def test_invalid_toml(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test an invalid toml file."""
monkeypatch.chdir(CONFIG_DATA / "invalid_toml")
Expand Down