summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2021-10-08 15:34:53 -0700
committerDavid Lord <davidism@gmail.com>2021-10-08 15:34:53 -0700
commit0a81393fdf41edb0ab9d2f527eccdc8ce38d7d42 (patch)
tree8ccab429eec551ec0278f61236e7fc0c07dc868b /tests
parent655918a61e22cade722dacb9bf798e86b13093af (diff)
parent96146c9d0b25d700d00b65c916739bd491dd15e0 (diff)
downloadclick-0a81393fdf41edb0ab9d2f527eccdc8ce38d7d42.tar.gz
Merge branch '8.0.x'
Diffstat (limited to 'tests')
-rw-r--r--tests/test_options.py52
1 files changed, 49 insertions, 3 deletions
diff --git a/tests/test_options.py b/tests/test_options.py
index efdda48..739da4e 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):
@@ -314,13 +314,36 @@ 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(["--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")
@@ -790,6 +813,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