Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
14 changes: 13 additions & 1 deletion pydocstringformatter/_configuration/toml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ def parse_toml_option(
if value is True:
return [action.option_strings[0]]
return []

if isinstance(action, argparse._StoreAction):
if isinstance(value, int):
value = str(value)
return [action.option_strings[0], value]
return [] # pragma: no cover

if isinstance(action, argparse._ExtendAction): # type: ignore[attr-defined]
out_args = []
if isinstance(value, list):
for item in value:
out_args += [action.option_strings[0], item]
else:
out_args = [action.option_strings[0], value]

return out_args

raise NotImplementedError # pragma: no cover


def parse_toml_file(
Expand Down
3 changes: 3 additions & 0 deletions tests/data/config/valid_toml_numpydoc/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pydocstringformatter]
write = false
style = 'numpydoc'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def func():
"""
A docstring"""
3 changes: 3 additions & 0 deletions tests/data/config/valid_toml_numpydoc_pep257/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pydocstringformatter]
write = false
style = ["numpydoc","pep257"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def func():
"""
A docstring"""
3 changes: 3 additions & 0 deletions tests/data/config/valid_toml_pep257/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pydocstringformatter]
write = false
style = 'pep257'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def func():
"""
A docstring"""
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,17 @@ def test_style_invalid_choice(self, capsys: pytest.CaptureFixture[str]) -> None:
output = capsys.readouterr()
assert not output.out
assert "--style: invalid choice: 'invalid'" in output.err

def test_style_in_toml(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that the style argument works in the toml file."""
monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc")
run = _Run(["test_package"])
assert ["numpydoc"] == run.config.style

monkeypatch.chdir(CONFIG_DATA / "valid_toml_pep257")
run = _Run(["test_package"])
assert ["pep257"] == run.config.style

monkeypatch.chdir(CONFIG_DATA / "valid_toml_numpydoc_pep257")
run = _Run(["test_package"])
assert all(x in run.config.style for x in ("pep257", "numpydoc"))