From 3d029e03eb2a793c64166cb1b690cd63e42461af Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 7 Oct 2021 07:02:00 -0700 Subject: count help doesn't show default range type --- tests/test_options.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_options.py b/tests/test_options.py index 53179e8..180468b 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -314,13 +314,21 @@ def test_dynamic_default_help_text(runner): (click.IntRange(max=32), "x<=32"), ], ) -def test_intrange_default_help_text(runner, type, expect): - option = click.Option(["--count"], type=type, show_default=True, default=2) +def test_intrange_default_help_text(type, expect): + option = click.Option(["--num"], type=type, show_default=True, default=2) context = click.Context(click.Command("test")) result = option.get_help_record(context)[1] assert expect in result +def test_count_default_type_help(): + """A count option with the default type should not show >=0 in help.""" + option = click.Option(["--couunt"], count=True, help="some words") + context = click.Context(click.Command("test")) + result = option.get_help_record(context)[1] + assert result == "some words" + + def test_toupper_envvar_prefix(runner): @click.command() @click.option("--arg") -- cgit v1.2.1 From f82ee1ff81bd466493d8746a0146065c306da747 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 8 Oct 2021 10:25:09 -0700 Subject: getting default value doesn't perform type cast --- tests/test_options.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_options.py b/tests/test_options.py index 180468b..06a70b4 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -252,7 +252,7 @@ def test_multiple_default_composite_type(): assert isinstance(opt.type, click.Tuple) assert opt.type.types == [click.INT, click.STRING] ctx = click.Context(click.Command("test")) - assert opt.get_default(ctx) == ((1, "a"),) + assert opt.type_cast_value(ctx, opt.get_default(ctx)) == ((1, "a"),) def test_parse_multiple_default_composite_type(runner): @@ -323,12 +323,27 @@ def test_intrange_default_help_text(type, expect): def test_count_default_type_help(): """A count option with the default type should not show >=0 in help.""" - option = click.Option(["--couunt"], count=True, help="some words") + option = click.Option(["--count"], count=True, help="some words") context = click.Context(click.Command("test")) result = option.get_help_record(context)[1] assert result == "some words" +def test_file_type_help_default(): + """The default for a File type is a filename string. The string + should be displayed in help, not an open file object. + + Type casting is only applied to defaults in processing, not when + getting the default value. + """ + option = click.Option( + ["--in"], type=click.File(), default=__file__, show_default=True + ) + context = click.Context(click.Command("test")) + result = option.get_help_record(context)[1] + assert __file__ in result + + def test_toupper_envvar_prefix(runner): @click.command() @click.option("--arg") -- cgit v1.2.1 From aa6f36017e5132836ea8679a4143a08944fa5c8c Mon Sep 17 00:00:00 2001 From: Ivan Kapelyukhin Date: Tue, 13 Jul 2021 21:49:39 +0200 Subject: option with multiple and flag_value replaces internal placeholder Co-authored-by: David Lord --- tests/test_options.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/test_options.py b/tests/test_options.py index 06a70b4..2e34337 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -792,6 +792,29 @@ def test_option_with_optional_value(runner, args, expect): assert result.return_value == expect +def test_multiple_option_with_optional_value(runner): + cli = click.Command( + "cli", + params=[ + click.Option(["-f"], is_flag=False, flag_value="flag", multiple=True), + click.Option(["-a"]), + click.Argument(["b"], nargs=-1), + ], + callback=lambda **kwargs: kwargs, + ) + result = runner.invoke( + cli, + ["-f", "-f", "other", "-f", "-a", "1", "a", "b"], + standalone_mode=False, + catch_exceptions=False, + ) + assert result.return_value == { + "f": ("flag", "other", "flag"), + "a": "1", + "b": ("a", "b"), + } + + def test_type_from_flag_value(): param = click.Option(["-a", "x"], default=True, flag_value=4) assert param.type is click.INT -- cgit v1.2.1