Skip to content

Commit e4a5285

Browse files
authored
Fix --help / -h (#57)
* Set up TDD * Quick Fix According to Click Doccs * Improve Test * Fix usage with config file * black * flake8 * Update config_file.py
1 parent f23eadb commit e4a5285

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docstr_coverage/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _assert_valid_key_value(k, v):
155155
# TODO: Use counting instead: https://click.palletsprojects.com/en/7.x/options/#counting
156156
"-v",
157157
"--verbose",
158-
type=click.Choice([0, 1, 2, 3, "0", "1", "2", "3"]),
158+
type=click.Choice(["0", "1", "2", "3"]),
159159
default="3",
160160
help="Verbosity level",
161161
show_default=True,

docstr_coverage/config_file.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def set_config_defaults(ctx, param, value):
2222
-------
2323
String
2424
Path to the configuration file"""
25-
if (value is not None) and os.path.exists(value):
25+
if value is not None and os.path.exists(value):
2626
with open(value) as f:
2727
config_data = yaml.safe_load(f) or {}
2828
ctx.params["config_file"] = value
@@ -34,6 +34,11 @@ def set_config_defaults(ctx, param, value):
3434
lambda config_paths: tuple([os.path.realpath(path) for path in config_paths]),
3535
)
3636
_extract_non_default_list(config_data, ctx, "ignore_patterns", lambda x: x)
37+
# TODO This can be removed as part PR #52 (verbose counting).
38+
# Until then, this is for compatibility with docs
39+
# which require verbose in config-file to be an int
40+
if "verbose" in config_data:
41+
config_data["verbose"] = str(config_data["verbose"])
3742
ctx.default_map = config_data
3843

3944
return value

tests/test_cli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,22 @@ def test_deprecations(paths, deprecated_option, runner: CliRunner):
536536
assert run_result.stdout.startswith(
537537
"Using deprecated {}".format(deprecated_option[0].split("=")[0])
538538
)
539+
540+
541+
@pytest.mark.parametrize(
542+
["help_flag"],
543+
[pytest.param(["--help"], id="long: --help"), pytest.param(["-h"], id="short: -h")],
544+
)
545+
def test_help_smoke(help_flag: str, runner: CliRunner):
546+
"""Smoke test which ensures that help is printed with exit code 0
547+
548+
Parameters
549+
----------
550+
help_flag:
551+
The (short or long) help path argument
552+
runner: CliRunner
553+
Click utility to invoke command line scripts"""
554+
run_result = runner.invoke(execute, help_flag)
555+
assert run_result.exit_code == 0
556+
assert isinstance(run_result.stdout, str)
557+
assert "Measure docstring coverage for" in run_result.stdout

0 commit comments

Comments
 (0)