Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed toml parser ignoring style #156

Merged
merged 16 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from 15 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]
jspaezp marked this conversation as resolved.
Show resolved Hide resolved
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:
jspaezp marked this conversation as resolved.
Show resolved Hide resolved
"""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 run.config.style == ["pep257", "numpydoc"]
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved