Skip to content
Myr

Parametrize deprecation tests and check targets (#3715)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rowlando13 · committed by GitHub · parents 5e906a8, 10b43c2 · Browse files · 1 file+57 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+57 added−15 removed

  • tests:+57 added−15 removed

1 file+57 added−15 removed

modified:tests/test_deprecations.py+57 added-15 removed
1import importlib.metadata23import pytest45import click6import click.core7import click.parser8import click.shell_completion9import click.utils10116@pytest.mark.parametrize("module", [click, click.utils], ids=["click", "click.utils"])7@pytest.mark.parametrize("name", ["get_binary_stream", "get_text_stream"])8def test_stream_helper_deprecated(module, name):9 with pytest.warns(DeprecationWarning, match=name):10 getattr(module, name)111212@pytest.mark.parametrize(14 "name",13 ("module", "name", "target"),14 [16 "LazyFile",17 "KeepOpenFile",18 "make_default_short_help",19 "PacifyFlushWrapper",20 "safecall",15 # Stream helpers, re-exported from both `click` and `click.utils`.16 (click, "get_binary_stream", click.utils._get_binary_stream),17 (click, "get_text_stream", click.utils._get_text_stream),18 (click.utils, "get_binary_stream", click.utils._get_binary_stream),19 (click.utils, "get_text_stream", click.utils._get_text_stream),20 # Command-class aliases, re-exported from `click` and `click.core`.21 (click, "BaseCommand", click.core._BaseCommand),22 (click, "MultiCommand", click.core._MultiCommand),23 (click.core, "BaseCommand", click.core._BaseCommand),24 (click.core, "MultiCommand", click.core._MultiCommand),25 # Old parser API (moved to `optparse`); `OptionParser` is also26 # re-exported from the top-level `click` namespace.27 (click, "OptionParser", click.parser._OptionParser),28 (click.parser, "OptionParser", click.parser._OptionParser),29 (click.parser, "Argument", click.parser._Argument),30 (click.parser, "Option", click.parser._Option),31 (click.parser, "split_opt", click.parser._split_opt),32 (click.parser, "normalize_opt", click.parser._normalize_opt),33 (click.parser, "ParsingState", click.parser._ParsingState),34 (click.parser, "split_arg_string", click.shell_completion.split_arg_string),35 # Deprecated `click.utils` utilities.36 (click.utils, "LazyFile", click.utils._LazyFile),37 (click.utils, "KeepOpenFile", click.utils._KeepOpenFile),38 (click.utils, "make_default_short_help", click.utils._make_default_short_help),39 (click.utils, "PacifyFlushWrapper", click.utils._PacifyFlushWrapper),40 (click.utils, "safecall", click.utils._safecall),41 # Version metadata attribute.42 (click, "__version__", importlib.metadata.version("click")),43 ],44 ids=lambda v: getattr(v, "__name__", v),45)23def test_utilities_deprecated(name):46def test_attr_deprecated(module, name, target):47 with pytest.warns(DeprecationWarning, match=name):25 getattr(click.utils, name)48 value = getattr(module, name)4950 assert value == target515253@pytest.mark.parametrize(54 "module",55 [click, click.core, click.parser, click.utils],56 ids=lambda m: m.__name__,57)58def test_unknown_attribute_raises(module):59 with pytest.raises(AttributeError, match="no_such_attribute"):60 _ = module.no_such_attribute616263def test_context_protected_args_deprecated():64 ctx = click.Context(click.Command("cli"))6566 with pytest.warns(DeprecationWarning, match="protected_args"):67 assert ctx.protected_args == []686970def test_isolated_filesystem_deprecated(runner):71 with pytest.warns(DeprecationWarning, match="isolated_filesystem"):72 with runner.isolated_filesystem():73 pass