Skip to content

Commit fa7eba6

Browse files
Fix missing deprecation logs and add tests (#49)
* Fix missing deprecation logs and add tests * Remove f-string for Python3.5 compatibility * Add `test_deprecations` documentation
1 parent 0a739dd commit fa7eba6

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

docstr_coverage/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,8 @@ def _assert_valid_key_value(k, v):
240240
is_eager=True,
241241
callback=set_config_defaults,
242242
)
243-
@click.option("--skipmagic", "skip_magic_old", is_flag=True, help="Deprecated. Use --skip-magic")
244-
@click.option(
245-
"--skipfiledoc", "skip_file_doc_old", is_flag=True, help="Deprecated. Use --skip-file-doc"
246-
)
243+
@click.option("--skipmagic", is_flag=True, help="Deprecated. Use --skip-magic")
244+
@click.option("--skipfiledoc", is_flag=True, help="Deprecated. Use --skip-file-doc")
247245
@click.option("--skipinit", is_flag=True, help="Deprecated. Use --skip-init")
248246
@click.option("--skipclassdef", is_flag=True, help="Deprecated. Use --skip-class-def")
249247
@click.option("--followlinks", is_flag=True, help="Deprecated. Use --follow-links")
@@ -270,7 +268,7 @@ def execute(paths, **kwargs):
270268

271269
# handle fail under
272270
if kwargs.get("failunder") is not None:
273-
if kwargs.get("fail_under") is not None:
271+
if kwargs.get("fail_under") != 100.0:
274272
raise ValueError("Should not set deprecated --failunder and --fail-under")
275273
click.secho("Using deprecated --failunder, should use --fail-under", fg="red")
276274
kwargs["fail_under"] = kwargs.pop("failunder")

tests/test_cli.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,36 @@ def test_accept_empty(
503503
assert run_result.exit_code == 0
504504
else:
505505
assert run_result.exit_code == 1
506+
507+
508+
##################################################
509+
# Deprecation Tests
510+
##################################################
511+
@pytest.mark.parametrize(["paths"], [pytest.param([SAMPLES_DIR])])
512+
@pytest.mark.parametrize(
513+
["deprecated_option"],
514+
[
515+
pytest.param(["--failunder=60"]),
516+
pytest.param(["--followlinks"]),
517+
pytest.param(["--skipclassdef"]),
518+
pytest.param(["--skipfiledoc"]),
519+
pytest.param(["--skipinit"]),
520+
pytest.param(["--skipmagic"]),
521+
],
522+
)
523+
def test_deprecations(paths, deprecated_option, runner: CliRunner):
524+
"""Test that using deprecated CLI options logs a warning
525+
526+
Parameters
527+
----------
528+
paths: List[str]
529+
Path arguments provided to CLI. These should be made absolute before they are passed to
530+
:func:`docstr_coverage.cli.collect_filepaths`
531+
deprecated_option: List[str]
532+
CLI option that has been deprecated
533+
runner: CliRunner
534+
Click utility to invoke command line scripts"""
535+
run_result = runner.invoke(execute, deprecated_option + paths)
536+
assert run_result.stdout.startswith(
537+
"Using deprecated {}".format(deprecated_option[0].split("=")[0])
538+
)

0 commit comments

Comments
 (0)