Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 11 additions & 3 deletions pydocstringformatter/_configuration/toml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import os
import sys
from argparse import _ExtendAction, _StoreAction, _StoreTrueAction
from typing import Any

from pydocstringformatter._utils.exceptions import TomlParsingError, UnrecognizedOption
Expand Down Expand Up @@ -41,15 +42,22 @@ def parse_toml_option(
except KeyError:
raise UnrecognizedOption(f"Don't recognize option {opt}") from exc

if isinstance(action, argparse._StoreTrueAction):
if isinstance(action, _StoreTrueAction):
if value is True:
return [action.option_strings[0]]
return []
if isinstance(action, argparse._StoreAction):

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

if isinstance(action, _ExtendAction):
if isinstance(value, str):
value = str(value)
return [action.option_strings[0], value]

raise NotImplementedError # pragma: no cover


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