Skip to content
Myr

test_bashcomplete.py

This file

Path

tests/test_bashcomplete.py

500 lines · 15.8 KiB · Python

Last changed by

apply blackDavid Lordbefore adoption93ba3ba

History of this file

Take it

The walk stopped after 200 commits: lines older than 950463b point at it.

Fix typo (#817)scottbeldenbefore adoption950463b

line 1why, one step back
1# -*- coding: utf-8 -*-

Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5

lines 2–3why, one step back
2import pytest
3

Fix typo (#817)scottbeldenbefore adoption950463b

lines 4–7why, one step back
4import click
5from click._bashcomplete import get_choices67

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 8why, one step back
8def choices_without_help(cli, args, incomplete):

apply blackDavid Lordbefore adoption93ba3ba

line 9why, one step back
9 completions = get_choices(cli, "dummy", args, incomplete)

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

lines 10–13why, one step back
10 return [c[0] for c in completions]
111213def choices_with_help(cli, args, incomplete):

apply blackDavid Lordbefore adoption93ba3ba

line 14why, one step back
14 return list(get_choices(cli, "dummy", args, incomplete))

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

lines 15–16why, one step back
15
16

Fix typo (#817)scottbeldenbefore adoption950463b

lines 17–18why, one step back
17def test_single_command():
18 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

line 19why, one step back
19 @click.option("--local-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 20–22why, one step back
20 def cli(local_opt):
21 pass22

apply blackDavid Lordbefore adoption93ba3ba

lines 23–24why, one step back
23 assert choices_without_help(cli, [], "-") == ["--local-opt"]
24 assert choices_without_help(cli, [], "") == []

Fix typo (#817)scottbeldenbefore adoption950463b

lines 25–28why, one step back
25
2627def test_boolean_flag():28 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

line 29why, one step back
29 @click.option("--shout/--no-shout", default=False)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 30–32why, one step back
30 def cli(local_opt):
31 pass32

apply blackDavid Lordbefore adoption93ba3ba

line 33why, one step back
33 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 34–37why, one step back
34
3536def test_multi_value_option():37 @click.group()

apply blackDavid Lordbefore adoption93ba3ba

line 38why, one step back
38 @click.option("--pos", nargs=2, type=float)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 39–42why, one step back
39 def cli(local_opt):
40 pass4142 @cli.command()

apply blackDavid Lordbefore adoption93ba3ba

line 43why, one step back
43 @click.option("--local-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 44–46why, one step back
44 def sub(local_opt):
45 pass46

apply blackDavid Lordbefore adoption93ba3ba

lines 47–50why, one step back
47 assert choices_without_help(cli, [], "-") == ["--pos"]
48 assert choices_without_help(cli, ["--pos"], "") == []49 assert choices_without_help(cli, ["--pos", "1.0"], "") == []50 assert choices_without_help(cli, ["--pos", "1.0", "1.0"], "") == ["sub"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 51–54why, one step back
51
5253def test_multi_option():54 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

line 55why, one step back
55 @click.option("--message", "-m", multiple=True)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 56–58why, one step back
56 def cli(local_opt):
57 pass58

apply blackDavid Lordbefore adoption93ba3ba

lines 59–60why, one step back
59 assert choices_without_help(cli, [], "-") == ["--message", "-m"]
60 assert choices_without_help(cli, ["-m"], "") == []

Fix typo (#817)scottbeldenbefore adoption950463b

lines 61–64why, one step back
61
6263def test_small_chain():64 @click.group()

apply blackDavid Lordbefore adoption93ba3ba

line 65why, one step back
65 @click.option("--global-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 66–69why, one step back
66 def cli(global_opt):
67 pass6869 @cli.command()

apply blackDavid Lordbefore adoption93ba3ba

line 70why, one step back
70 @click.option("--local-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 71–73why, one step back
71 def sub(local_opt):
72 pass73

apply blackDavid Lordbefore adoption93ba3ba

lines 74–77why, one step back
74 assert choices_without_help(cli, [], "") == ["sub"]
75 assert choices_without_help(cli, [], "-") == ["--global-opt"]76 assert choices_without_help(cli, ["sub"], "") == []77 assert choices_without_help(cli, ["sub"], "-") == ["--local-opt"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 78–80why, one step back
78
7980def test_long_chain():

apply blackDavid Lordbefore adoption93ba3ba

lines 81–82why, one step back
81 @click.group("cli")
82 @click.option("--cli-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 83–85why, one step back
83 def cli(cli_opt):
84 pass85

apply blackDavid Lordbefore adoption93ba3ba

lines 86–87why, one step back
86 @cli.group("asub")
87 @click.option("--asub-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 88–90why, one step back
88 def asub(asub_opt):
89 pass90

apply blackDavid Lordbefore adoption93ba3ba

lines 91–92why, one step back
91 @asub.group("bsub")
92 @click.option("--bsub-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 93–95why, one step back
93 def bsub(bsub_opt):
94 pass95

apply blackDavid Lordbefore adoption93ba3ba

lines 96–97why, one step back
96 COLORS = ["red", "green", "blue"]
97

Fix typo (#817)scottbeldenbefore adoption950463b

lines 98–99why, one step back
98 def get_colors(ctx, args, incomplete):
99 for c in COLORS:

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 100–101why, one step back
100 if c.startswith(incomplete):
101 yield c

Fix typo (#817)scottbeldenbefore adoption950463b

line 102why, one step back
102

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 103–107why, one step back
103 def search_colors(ctx, args, incomplete):
104 for c in COLORS:105 if incomplete in c:106 yield c107

apply blackDavid Lordbefore adoption93ba3ba

lines 108–115why, one step back
108 CSUB_OPT_CHOICES = ["foo", "bar"]
109 CSUB_CHOICES = ["bar", "baz"]110111 @bsub.command("csub")112 @click.option("--csub-opt", type=click.Choice(CSUB_OPT_CHOICES))113 @click.option("--csub", type=click.Choice(CSUB_CHOICES))114 @click.option("--search-color", autocompletion=search_colors)115 @click.argument("color", autocompletion=get_colors)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 116–118why, one step back
116 def csub(csub_opt, color):
117 pass118

apply blackDavid Lordbefore adoption93ba3ba

lines 119–149why, one step back
119 assert choices_without_help(cli, [], "-") == ["--cli-opt"]
120 assert choices_without_help(cli, [], "") == ["asub"]121 assert choices_without_help(cli, ["asub"], "-") == ["--asub-opt"]122 assert choices_without_help(cli, ["asub"], "") == ["bsub"]123 assert choices_without_help(cli, ["asub", "bsub"], "-") == ["--bsub-opt"]124 assert choices_without_help(cli, ["asub", "bsub"], "") == ["csub"]125 assert choices_without_help(cli, ["asub", "bsub", "csub"], "-") == [126 "--csub-opt",127 "--csub",128 "--search-color",129 ]130 assert (131 choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "")132 == CSUB_OPT_CHOICES133 )134 assert choices_without_help(cli, ["asub", "bsub", "csub"], "--csub") == [135 "--csub-opt",136 "--csub",137 ]138 assert (139 choices_without_help(cli, ["asub", "bsub", "csub", "--csub"], "")140 == CSUB_CHOICES141 )142 assert choices_without_help(cli, ["asub", "bsub", "csub", "--csub-opt"], "f") == [143 "foo"144 ]145 assert choices_without_help(cli, ["asub", "bsub", "csub"], "") == COLORS146 assert choices_without_help(cli, ["asub", "bsub", "csub"], "b") == ["blue"]147 assert choices_without_help(148 cli, ["asub", "bsub", "csub", "--search-color"], "een"149 ) == ["green"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 150–152why, one step back
150
151152def test_chaining():

apply blackDavid Lordbefore adoption93ba3ba

lines 153–155why, one step back
153 @click.group("cli", chain=True)
154 @click.option("--cli-opt")155 @click.argument("arg", type=click.Choice(["cliarg1", "cliarg2"]))

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

line 156why, one step back
156 def cli(cli_opt, arg):

Fix typo (#817)scottbeldenbefore adoption950463b

lines 157–158why, one step back
157 pass
158

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 159why, one step back
159 @cli.command()

apply blackDavid Lordbefore adoption93ba3ba

line 160why, one step back
160 @click.option("--asub-opt")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 161–163why, one step back
161 def asub(asub_opt):
162 pass163

apply blackDavid Lordbefore adoption93ba3ba

lines 164–166why, one step back
164 @cli.command(help="bsub help")
165 @click.option("--bsub-opt")166 @click.argument("arg", type=click.Choice(["arg1", "arg2"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 167–169why, one step back
167 def bsub(bsub_opt, arg):
168 pass169

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 170why, one step back
170 @cli.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 171–172why, one step back
171 @click.option("--csub-opt")
172 @click.argument("arg", type=click.Choice(["carg1", "carg2"]), default="carg1")

Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849

lines 173–175why, one step back
173 def csub(csub_opt, arg):
174 pass175

apply blackDavid Lordbefore adoption93ba3ba

lines 176–195why, one step back
176 assert choices_without_help(cli, [], "-") == ["--cli-opt"]
177 assert choices_without_help(cli, [], "") == ["cliarg1", "cliarg2"]178 assert choices_without_help(cli, ["cliarg1", "asub"], "-") == ["--asub-opt"]179 assert choices_without_help(cli, ["cliarg1", "asub"], "") == ["bsub", "csub"]180 assert choices_without_help(cli, ["cliarg1", "bsub"], "") == ["arg1", "arg2"]181 assert choices_without_help(cli, ["cliarg1", "asub", "--asub-opt"], "") == []182 assert choices_without_help(183 cli, ["cliarg1", "asub", "--asub-opt", "5", "bsub"], "-"184 ) == ["--bsub-opt"]185 assert choices_without_help(cli, ["cliarg1", "asub", "bsub"], "-") == ["--bsub-opt"]186 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "") == [187 "carg1",188 "carg2",189 ]190 assert choices_without_help(cli, ["cliarg1", "bsub", "arg1", "csub"], "") == [191 "carg1",192 "carg2",193 ]194 assert choices_without_help(cli, ["cliarg1", "asub", "csub"], "-") == ["--csub-opt"]195 assert choices_with_help(cli, ["cliarg1", "asub"], "b") == [("bsub", "bsub help")]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 196–199why, one step back
196
197198def test_argument_choice():199 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 200–202why, one step back
200 @click.argument("arg1", required=True, type=click.Choice(["arg11", "arg12"]))
201 @click.argument("arg2", type=click.Choice(["arg21", "arg22"]), default="arg21")202 @click.argument("arg3", type=click.Choice(["arg", "argument"]), default="arg")

Fix typo (#817)scottbeldenbefore adoption950463b

lines 203–205why, one step back
203 def cli():
204 pass205

apply blackDavid Lordbefore adoption93ba3ba

lines 206–210why, one step back
206 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]
207 assert choices_without_help(cli, [], "arg") == ["arg11", "arg12"]208 assert choices_without_help(cli, ["arg11"], "") == ["arg21", "arg22"]209 assert choices_without_help(cli, ["arg12", "arg21"], "") == ["arg", "argument"]210 assert choices_without_help(cli, ["arg12", "arg21"], "argu") == ["argument"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 211–214why, one step back
211
212213def test_option_choice():214 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 215–217why, one step back
215 @click.option("--opt1", type=click.Choice(["opt11", "opt12"]), help="opt1 help")
216 @click.option("--opt2", type=click.Choice(["opt21", "opt22"]), default="opt21")217 @click.option("--opt3", type=click.Choice(["opt", "option"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 218–220why, one step back
218 def cli():
219 pass220

apply blackDavid Lordbefore adoption93ba3ba

lines 221–240why, one step back
221 assert choices_with_help(cli, [], "-") == [
222 ("--opt1", "opt1 help"),223 ("--opt2", None),224 ("--opt3", None),225 ]226 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2", "--opt3"]227 assert choices_without_help(cli, [], "--opt1=") == ["opt11", "opt12"]228 assert choices_without_help(cli, [], "--opt2=") == ["opt21", "opt22"]229 assert choices_without_help(cli, ["--opt2"], "=") == ["opt21", "opt22"]230 assert choices_without_help(cli, ["--opt2", "="], "opt") == ["opt21", "opt22"]231 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]232 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]233 assert choices_without_help(cli, ["--opt1", "opt11", "--opt2"], "") == [234 "opt21",235 "opt22",236 ]237 assert choices_without_help(cli, ["--opt2", "opt21"], "-") == ["--opt1", "--opt3"]238 assert choices_without_help(cli, ["--opt1", "opt11"], "-") == ["--opt2", "--opt3"]239 assert choices_without_help(cli, ["--opt1"], "opt") == ["opt11", "opt12"]240 assert choices_without_help(cli, ["--opt3"], "opti") == ["option"]

Fix typo (#817)scottbeldenbefore adoption950463b

line 241why, one step back
241

apply blackDavid Lordbefore adoption93ba3ba

lines 242–245why, one step back
242 assert choices_without_help(cli, ["--opt1", "invalid_opt"], "-") == [
243 "--opt2",244 "--opt3",245 ]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 246–249why, one step back
246
247248def test_option_and_arg_choice():249 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 250–252why, one step back
250 @click.option("--opt1", type=click.Choice(["opt11", "opt12"]))
251 @click.argument("arg1", required=False, type=click.Choice(["arg11", "arg12"]))252 @click.option("--opt2", type=click.Choice(["opt21", "opt22"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 253–255why, one step back
253 def cli():
254 pass255

apply blackDavid Lordbefore adoption93ba3ba

lines 256–261why, one step back
256 assert choices_without_help(cli, ["--opt1"], "") == ["opt11", "opt12"]
257 assert choices_without_help(cli, [""], "--opt1=") == ["opt11", "opt12"]258 assert choices_without_help(cli, [], "") == ["arg11", "arg12"]259 assert choices_without_help(cli, ["--opt2"], "") == ["opt21", "opt22"]260 assert choices_without_help(cli, ["arg11"], "--opt") == ["--opt1", "--opt2"]261 assert choices_without_help(cli, [], "--opt") == ["--opt1", "--opt2"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 262–265why, one step back
262
263264def test_boolean_flag_choice():265 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 266–267why, one step back
266 @click.option("--shout/--no-shout", default=False)
267 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 268–270why, one step back
268 def cli(local_opt):
269 pass270

apply blackDavid Lordbefore adoption93ba3ba

lines 271–272why, one step back
271 assert choices_without_help(cli, [], "-") == ["--shout", "--no-shout"]
272 assert choices_without_help(cli, ["--shout"], "") == ["arg1", "arg2"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 273–276why, one step back
273
274275def test_multi_value_option_choice():276 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 277–278why, one step back
277 @click.option("--pos", nargs=2, type=click.Choice(["pos1", "pos2"]))
278 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 279–281why, one step back
279 def cli(local_opt):
280 pass281

apply blackDavid Lordbefore adoption93ba3ba

lines 282–285why, one step back
282 assert choices_without_help(cli, ["--pos"], "") == ["pos1", "pos2"]
283 assert choices_without_help(cli, ["--pos", "pos1"], "") == ["pos1", "pos2"]284 assert choices_without_help(cli, ["--pos", "pos1", "pos2"], "") == ["arg1", "arg2"]285 assert choices_without_help(cli, ["--pos", "pos1", "pos2", "arg1"], "") == []

Fix typo (#817)scottbeldenbefore adoption950463b

lines 286–289why, one step back
286
287288def test_multi_option_choice():289 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 290–291why, one step back
290 @click.option("--message", "-m", multiple=True, type=click.Choice(["m1", "m2"]))
291 @click.argument("arg", required=False, type=click.Choice(["arg1", "arg2"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 292–294why, one step back
292 def cli(local_opt):
293 pass294

apply blackDavid Lordbefore adoption93ba3ba

lines 295–297why, one step back
295 assert choices_without_help(cli, ["-m"], "") == ["m1", "m2"]
296 assert choices_without_help(cli, ["-m", "m1", "-m"], "") == ["m1", "m2"]297 assert choices_without_help(cli, ["-m", "m1"], "") == ["arg1", "arg2"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 298–301why, one step back
298
299300def test_variadic_argument_choice():301 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 302–303why, one step back
302 @click.option("--opt", type=click.Choice(["opt1", "opt2"]))
303 @click.argument("src", nargs=-1, type=click.Choice(["src1", "src2"]))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 304–306why, one step back
304 def cli(local_opt):
305 pass306

apply blackDavid Lordbefore adoption93ba3ba

lines 307–310why, one step back
307 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]
308 assert choices_without_help(cli, ["src1", "src2"], "--o") == ["--opt"]309 assert choices_without_help(cli, ["src1", "src2", "--opt"], "") == ["opt1", "opt2"]310 assert choices_without_help(cli, ["src1", "src2"], "") == ["src1", "src2"]

Fix typo (#817)scottbeldenbefore adoption950463b

lines 311–312why, one step back
311
312

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 313–314why, one step back
313def test_variadic_argument_complete():
314 def _complete(ctx, args, incomplete):

apply blackDavid Lordbefore adoption93ba3ba

line 315why, one step back
315 return ["abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz"]

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 316–321why, one step back
316
317 @click.group()318 def entrypoint():319 pass320321 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 322–323why, one step back
322 @click.option("--opt", autocompletion=_complete)
323 @click.argument("arg", nargs=-1)

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 324–328why, one step back
324 def subcommand(opt, arg):
325 pass326327 entrypoint.add_command(subcommand)328

apply blackDavid Lordbefore adoption93ba3ba

lines 329–338why, one step back
329 assert choices_without_help(entrypoint, ["subcommand", "--opt"], "") == _complete(
330 0, 0, 0331 )332 assert choices_without_help(333 entrypoint, ["subcommand", "whatever", "--opt"], ""334 ) == _complete(0, 0, 0)335 assert (336 choices_without_help(entrypoint, ["subcommand", "whatever", "--opt", "abc"], "")337 == []338 )

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 339–340why, one step back
339
340

Fix typo (#817)scottbeldenbefore adoption950463b

lines 341–345why, one step back
341def test_long_chain_choice():
342 @click.group()343 def cli():344 pass345

Merge pull request #869 from stopthatcow/feature/866David Lordbefore adoptiond37ff75

line 346why, one step back
346 @cli.group()

apply blackDavid Lordbefore adoption93ba3ba

lines 347–350why, one step back
347 @click.option("--sub-opt", type=click.Choice(["subopt1", "subopt2"]))
348 @click.argument(349 "sub-arg", required=False, type=click.Choice(["subarg1", "subarg2"])350 )

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

line 351why, one step back
351 def sub(sub_opt, sub_arg):

Fix typo (#817)scottbeldenbefore adoption950463b

lines 352–353why, one step back
352 pass
353

apply blackDavid Lordbefore adoption93ba3ba

lines 354–361why, one step back
354 @sub.command(short_help="bsub help")
355 @click.option("--bsub-opt", type=click.Choice(["bsubopt1", "bsubopt2"]))356 @click.argument(357 "bsub-arg1", required=False, type=click.Choice(["bsubarg1", "bsubarg2"])358 )359 @click.argument(360 "bbsub-arg2", required=False, type=click.Choice(["bbsubarg1", "bbsubarg2"])361 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 362–364why, one step back
362 def bsub(bsub_opt):
363 pass364

apply blackDavid Lordbefore adoption93ba3ba

line 365why, one step back
365 @sub.group("csub")

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 366–372why, one step back
366 def csub():
367 pass368369 @csub.command()370 def dsub():371 pass372

apply blackDavid Lordbefore adoption93ba3ba

lines 373–408why, one step back
373 assert choices_with_help(cli, ["sub", "subarg1"], "") == [
374 ("bsub", "bsub help"),375 ("csub", ""),376 ]377 assert choices_without_help(cli, ["sub"], "") == ["subarg1", "subarg2"]378 assert choices_without_help(cli, ["sub", "--sub-opt"], "") == ["subopt1", "subopt2"]379 assert choices_without_help(cli, ["sub", "--sub-opt", "subopt1"], "") == [380 "subarg1",381 "subarg2",382 ]383 assert choices_without_help(384 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], "-"385 ) == ["--bsub-opt"]386 assert choices_without_help(387 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub"], ""388 ) == ["bsubarg1", "bsubarg2"]389 assert choices_without_help(390 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "bsub", "--bsub-opt"], ""391 ) == ["bsubopt1", "bsubopt2"]392 assert choices_without_help(393 cli,394 [395 "sub",396 "--sub-opt",397 "subopt1",398 "subarg1",399 "bsub",400 "--bsub-opt",401 "bsubopt1",402 "bsubarg1",403 ],404 "",405 ) == ["bbsubarg1", "bbsubarg2"]406 assert choices_without_help(407 cli, ["sub", "--sub-opt", "subopt1", "subarg1", "csub"], ""408 ) == ["dsub"]

Merge pull request #930 from stopthatcow/feature/925David Lordbefore adoptionbe28b6c

lines 409–435why, one step back
409
410411def test_chained_multi():412 @click.group()413 def cli():414 pass415416 @cli.group()417 def sub():418 pass419420 @sub.group()421 def bsub():422 pass423424 @sub.group(chain=True)425 def csub():426 pass427428 @csub.command()429 def dsub():430 pass431432 @csub.command()433 def esub():434 pass435

apply blackDavid Lordbefore adoption93ba3ba

lines 436–439why, one step back
436 assert choices_without_help(cli, ["sub"], "") == ["bsub", "csub"]
437 assert choices_without_help(cli, ["sub"], "c") == ["csub"]438 assert choices_without_help(cli, ["sub", "csub"], "") == ["dsub", "esub"]439 assert choices_without_help(cli, ["sub", "csub", "dsub"], "") == ["esub"]

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 440–443why, one step back
440
441442def test_hidden():443 @click.group()

apply blackDavid Lordbefore adoption93ba3ba

lines 444–445why, one step back
444 @click.option("--name", hidden=True)
445 @click.option("--choices", type=click.Choice([1, 2]), hidden=True)

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 446–461why, one step back
446 def cli(name):
447 pass448449 @cli.group(hidden=True)450 def hgroup():451 pass452453 @hgroup.group()454 def hgroupsub():455 pass456457 @cli.command()458 def asub():459 pass460461 @cli.command(hidden=True)

apply blackDavid Lordbefore adoption93ba3ba

line 462why, one step back
462 @click.option("--hname")

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

lines 463–465why, one step back
463 def hsub():
464 pass465

apply blackDavid Lordbefore adoption93ba3ba

lines 466–467why, one step back
466 assert choices_without_help(cli, [], "--n") == []
467 assert choices_without_help(cli, [], "--c") == []

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

line 468why, one step back
468 # If the user exactly types out the hidden param, complete its options.

apply blackDavid Lordbefore adoption93ba3ba

lines 469–472why, one step back
469 assert choices_without_help(cli, ["--choices"], "") == [1, 2]
470 assert choices_without_help(cli, [], "") == ["asub"]471 assert choices_without_help(cli, [], "") == ["asub"]472 assert choices_without_help(cli, [], "h") == []

Merge pull request #1061 from stopthatcow/feature/1058David Lordbefore adoption752c5e4

line 473why, one step back
473 # If the user exactly types out the hidden command, complete its subcommands.

apply blackDavid Lordbefore adoption93ba3ba

lines 474–475why, one step back
474 assert choices_without_help(cli, ["hgroup"], "") == ["hgroupsub"]
475 assert choices_without_help(cli, ["hsub"], "--h") == ["--hname"]

Merge pull request #1248 from bertolinocastro/masterDavid Lordbefore adoption29e7de5

lines 476–500why, one step back
476
477478@pytest.mark.parametrize(479 ("args", "part", "expect"),480 [481 ([], "-", ["--opt"]),482 (["value"], "--", ["--opt"]),483 ([], "-o", []),484 (["--opt"], "-o", []),485 (["--"], "", ["name", "-o", "--opt", "--"]),486 (["--"], "--o", ["--opt"]),487 ],488)489def test_args_with_double_dash_complete(args, part, expect):490 def _complete(ctx, args, incomplete):491 values = ["name", "-o", "--opt", "--"]492 return [x for x in values if x.startswith(incomplete)]493494 @click.command()495 @click.option("--opt")496 @click.argument("args", nargs=-1, autocompletion=_complete)497 def cli(opt, args):498 pass499500 assert choices_without_help(cli, args, part) == expect