diff options
author | David Lord <davidism@gmail.com> | 2020-10-10 17:37:55 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-10-10 18:39:36 -0700 |
commit | e79c2b47aa5b456e6c70f980ecf0f883447eb340 (patch) | |
tree | 84fd27416085be6fba05eeabe4a5ffefd8112b38 /tests/test_shell_completion.py | |
parent | 94cc293e1bc6899cead8f8051375969a41658cf3 (diff) | |
download | click-e79c2b47aa5b456e6c70f980ecf0f883447eb340.tar.gz |
get default before processing value
This ensures the default value is processed like other values. Some
type converters were adjusted to accept values that are already the
correct type.
Use parameter source instead of value to determine if argument was
supplied on the command line during completion.
Add a parameter source for values from prompt.
Diffstat (limited to 'tests/test_shell_completion.py')
-rw-r--r-- | tests/test_shell_completion.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/test_shell_completion.py b/tests/test_shell_completion.py index 5c169a9..e85dc32 100644 --- a/tests/test_shell_completion.py +++ b/tests/test_shell_completion.py @@ -90,6 +90,21 @@ def test_argument_order(): assert _get_words(cli, ["x", "b"], "d") == ["d"] +def test_argument_default(): + cli = Command( + "cli", + add_help_option=False, + params=[ + Argument(["a"], type=Choice(["a"]), default="a"), + Argument(["b"], type=Choice(["b"]), default="b"), + ], + ) + assert _get_words(cli, [], "") == ["a"] + assert _get_words(cli, ["a"], "b") == ["b"] + # ignore type validation + assert _get_words(cli, ["x"], "b") == ["b"] + + def test_type_choice(): cli = Command("cli", params=[Option(["-c"], type=Choice(["a1", "a2", "b"]))]) assert _get_words(cli, ["-c"], "") == ["a1", "a2", "b"] @@ -119,9 +134,9 @@ def test_option_flag(): Argument(["a"], type=Choice(["a1", "a2", "b"])), ], ) - assert _get_words(cli, ["type"], "--") == ["--on", "--off"] + assert _get_words(cli, [], "--") == ["--on", "--off"] # flag option doesn't take value, use choice argument - assert _get_words(cli, ["x", "--on"], "a") == ["a1", "a2"] + assert _get_words(cli, ["--on"], "a") == ["a1", "a2"] def test_option_custom(): |