Skip to content

Commit

Permalink
Fix incorrect pyproject.toml parsing of boolean values (#133)
Browse files Browse the repository at this point in the history
* fix: boolean options read properly from pyproject

* test: add tests to explicitly check pyproject options
  • Loading branch information
weibullguy committed Dec 16, 2022
1 parent d81298b commit c7ee0f3
Show file tree
Hide file tree
Showing 3 changed files with 592 additions and 25 deletions.
32 changes: 19 additions & 13 deletions src/docformatter/configuration.py
Expand Up @@ -113,7 +113,8 @@ def do_parse_arguments(self) -> None:
"-r",
"--recursive",
action="store_true",
default=bool(self.flargs_dct.get("recursive", False)),
default=self.flargs_dct.get("recursive", "false").lower()
== "true",
help="drill down directories recursively",
)
self.parser.add_argument(
Expand Down Expand Up @@ -141,7 +142,8 @@ def do_parse_arguments(self) -> None:
self.parser.add_argument(
"--force-wrap",
action="store_true",
default=bool(self.flargs_dct.get("force-wrap", False)),
default=self.flargs_dct.get("force-wrap", "false").lower()
== "true",
help="force descriptions to be wrapped even if it may "
"result in a mess (default: False)",
)
Expand All @@ -158,38 +160,42 @@ def do_parse_arguments(self) -> None:
"--blank",
dest="post_description_blank",
action="store_true",
default=bool(self.flargs_dct.get("blank", False)),
default=self.flargs_dct.get("blank", "false").lower() == "true",
help="add blank line after description (default: False)",
)
self.parser.add_argument(
"--pre-summary-newline",
action="store_true",
default=bool(self.flargs_dct.get("pre-summary-newline", False)),
default=self.flargs_dct.get("pre-summary-newline", "false").lower()
== "true",
help="add a newline before the summary of a multi-line docstring "
"(default: False)",
)
self.parser.add_argument(
"--pre-summary-space",
action="store_true",
default=bool(self.flargs_dct.get("pre-summary-space", False)),
default=self.flargs_dct.get("pre-summary-space", "false").lower()
== "true",
help="add a space after the opening triple quotes "
"(default: False)",
)
self.parser.add_argument(
"--make-summary-multi-line",
action="store_true",
default=bool(
self.flargs_dct.get("make-summary-multi-line", False)
),
default=self.flargs_dct.get(
"make-summary-multi-line", "false"
).lower()
== "true",
help="add a newline before and after the summary of a one-line "
"docstring (default: False)",
)
self.parser.add_argument(
"--close-quotes-on-newline",
action="store_true",
default=bool(
self.flargs_dct.get("close-quotes-on-newline", False)
),
default=self.flargs_dct.get(
"close-quotes-on-newline", "false"
).lower()
== "true",
help="place closing triple quotes on a new-line when a "
"one-line docstring wraps to two or more lines "
"(default: False)",
Expand Down Expand Up @@ -217,7 +223,8 @@ def do_parse_arguments(self) -> None:
self.parser.add_argument(
"--non-strict",
action="store_true",
default=bool(self.flargs_dct.get("non-strict", False)),
default=self.flargs_dct.get("non-strict", "false").lower()
== "true",
help="don't strictly follow reST syntax to identify lists (see "
"issue #67) (default: False)",
)
Expand All @@ -238,7 +245,6 @@ def do_parse_arguments(self) -> None:
)

self.args = self.parser.parse_args(self.args_lst[1:])

if self.args.line_range:
if self.args.line_range[0] <= 0:
self.parser.error("--range must be positive numbers")
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Expand Up @@ -64,6 +64,17 @@ def temporary_file(contents, file_directory=".", file_prefix=""):
finally:
os.remove(f.name)

@pytest.fixture(scope="function")
def temporary_config(config, file_directory="/tmp",
file_name="pyproject.toml"):
"""Write contents to temporary configuration and yield it."""
f = open(f"{file_directory}/{file_name}", "wb")
try:
f.write(config.encode())
f.close()
yield f.name
finally:
os.remove(f.name)

@pytest.fixture(scope="function")
def run_docformatter(arguments, temporary_file):
Expand Down

0 comments on commit c7ee0f3

Please sign in to comment.