Parametrize deprecation tests and check targets
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kevin Deldycke · committed by Kevin Deldycke · parent cfa01ee · 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
Provenance
- Commit
10b43c2- Tree
e1e2160- Author
Kevin Deldycke <kevin@deldycke.com>- Committer
Kevin Deldycke <kevin@deldycke.com>- Parent
cfa01ee
1 file changed+57 added−15 removed
modified:tests/test_deprecations.py+57 added-15 removed
1+import importlib.metadata2+3 import pytest4 5 import click6+import click.core7+import click.parser8+import click.shell_completion9+import click.utils10 11 6-@pytest.mark.parametrize("module", [click, click.utils], ids=["click", "click.utils"])7-@pytest.mark.parametrize("name", ["get_binary_stream", "get_text_stream"])8-def test_stream_helper_deprecated(module, name):9- with pytest.warns(DeprecationWarning, match=name):10- getattr(module, name)11-12-12 @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 )23-def test_utilities_deprecated(name):46+def test_attr_deprecated(module, name, target):47 with pytest.warns(DeprecationWarning, match=name):25- getattr(click.utils, name)48+ value = getattr(module, name)49 50+ assert value == target51 52+53+@pytest.mark.parametrize(54+ "module",55+ [click, click.core, click.parser, click.utils],56+ ids=lambda m: m.__name__,57+)58+def test_unknown_attribute_raises(module):59+ with pytest.raises(AttributeError, match="no_such_attribute"):60+ _ = module.no_such_attribute61+62+63+def test_context_protected_args_deprecated():64+ ctx = click.Context(click.Command("cli"))65+66+ with pytest.warns(DeprecationWarning, match="protected_args"):67+ assert ctx.protected_args == []68+69+70 def test_isolated_filesystem_deprecated(runner):71 with pytest.warns(DeprecationWarning, match="isolated_filesystem"):72 with runner.isolated_filesystem():73 pass