test_arguments.py
This file
Path
tests/test_arguments.py
374 lines · 10.1 KiB · Python
Last changed by
Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
History of this fileTake it
The walk stopped after 200 commits: lines older than 43cb986 point at it.
Merge branch '7.x'David Lordbefore adoption7239794
lines 1–2why, one step back1import sys2Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523
line 3why, one step back3import pytestMerge branch '7.x'David Lordbefore adoption7239794
line 4why, one step back4Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 5–9why, one step back5import click678def test_nargs_star(runner):9 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 10–11why, one step back10 @click.argument("src", nargs=-1)11 @click.argument("dst")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 12why, one step back12 def copy(src, dst):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 13–14why, one step back13 click.echo(f"src={'|'.join(src)}")14 click.echo(f"dst={dst}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 15why, one step back15Merge branch '7.x'David Lordbefore adoption7239794
line 16why, one step back16 result = runner.invoke(copy, ["foo.txt", "bar.txt", "dir"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 17why, one step back17 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 18why, one step back18 assert result.output.splitlines() == ["src=foo.txt|bar.txt", "dst=dir"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 19–20why, one step back1920Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
line 21why, one step back21def test_argument_unbounded_nargs_cant_have_default(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 22–23why, one step back22 with pytest.raises(TypeError, match="nargs=-1"):23Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 24why, one step back24 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 25why, one step back25 @click.argument("src", nargs=-1, default=42)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 26–31why, one step back26 def copy(src):27 pass282930def test_nargs_tup(runner):31 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 32–33why, one step back32 @click.argument("name", nargs=1)33 @click.argument("point", nargs=2, type=click.INT)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 34why, one step back34 def copy(name, point):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 35–37why, one step back35 click.echo(f"name={name}")36 x, y = point37 click.echo(f"point={x}/{y}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 38why, one step back38Merge branch '7.x'David Lordbefore adoption7239794
line 39why, one step back39 result = runner.invoke(copy, ["peter", "1", "2"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 40why, one step back40 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 41why, one step back41 assert result.output.splitlines() == ["name=peter", "point=1/2"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 42–52why, one step back424344def test_nargs_tup_composite(runner):45 variations = [46 dict(type=(str, int)),47 dict(type=click.Tuple([str, int])),48 dict(nargs=2, type=click.Tuple([str, int])),49 dict(nargs=2, type=(str, int)),50 ]5152 for opts in variations:Merge branch '7.x'David Lordbefore adoption7239794
line 53why, one step back53Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 54why, one step back54 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 55why, one step back55 @click.argument("item", **opts)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 56why, one step back56 def copy(item):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 57–58why, one step back57 name, id = item58 click.echo(f"name={name} id={id:d}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 59why, one step back59Merge branch '7.x'David Lordbefore adoption7239794
line 60why, one step back60 result = runner.invoke(copy, ["peter", "1"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 61why, one step back61 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 62why, one step back62 assert result.output.splitlines() == ["name=peter id=1"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 63–66why, one step back636465def test_nargs_err(runner):66 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 67why, one step back67 @click.argument("x")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 68–70why, one step back68 def copy(x):69 click.echo(x)70Merge branch '7.x'David Lordbefore adoption7239794
line 71why, one step back71 result = runner.invoke(copy, ["foo"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 72why, one step back72 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 73why, one step back73 assert result.output == "foo\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 74why, one step back74Merge branch '7.x'David Lordbefore adoption7239794
line 75why, one step back75 result = runner.invoke(copy, ["foo", "bar"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 76why, one step back76 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 77why, one step back77 assert "Got unexpected extra argument (bar)" in result.outputMerge branch '7.x'David Lordbefore adoption8f36eab
lines 78–81why, one step back787980def test_bytes_args(runner, monkeypatch):81 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 82why, one step back82 @click.argument("arg")Merge branch '7.x'David Lordbefore adoption8f36eab
line 83why, one step back83 def from_bytes(arg):Merge branch '7.x'David Lordbefore adoption7239794
line 84why, one step back84 assert isinstance(Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 85why, one step back85 arg, strMerge branch '7.x'David Lordbefore adoption7239794
line 86why, one step back86 ), "UTF-8 encoded argument should be implicitly converted to Unicode"Merge branch '7.x'David Lordbefore adoption8f36eab
lines 87–88why, one step back8788 # Simulate empty locale environment variablesMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 89–91why, one step back89 monkeypatch.setattr(sys.stdin, "encoding", "utf-8")90 monkeypatch.setattr(sys, "getfilesystemencoding", lambda: "utf-8")91 monkeypatch.setattr(sys, "getdefaultencoding", lambda: "utf-8")Merge branch '7.x'David Lordbefore adoption8f36eab
line 92why, one step back92Merge branch '7.x'David Lordbefore adoption7239794
lines 93–94why, one step back93 runner.invoke(94 from_bytes,Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 95why, one step back95 ["Something outside of ASCII range: 林".encode()],Merge branch '7.x'David Lordbefore adoption7239794
lines 96–97why, one step back96 catch_exceptions=False,97 )Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 98–101why, one step back9899100def test_file_args(runner):101 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 102–103why, one step back102 @click.argument("input", type=click.File("rb"))103 @click.argument("output", type=click.File("wb"))Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 104–111why, one step back104 def inout(input, output):105 while True:106 chunk = input.read(1024)107 if not chunk:108 break109 output.write(chunk)110111 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 112–113why, one step back112 result = runner.invoke(inout, ["-", "hello.txt"], input="Hey!")113 assert result.output == ""Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 114why, one step back114 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 115–116why, one step back115 with open("hello.txt", "rb") as f:116 assert f.read() == b"Hey!"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 117why, one step back117Merge branch '7.x'David Lordbefore adoption7239794
lines 118–119why, one step back118 result = runner.invoke(inout, ["hello.txt", "-"])119 assert result.output == "Hey!"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 120–124why, one step back120 assert result.exit_code == 0121122123def test_path_args(runner):124 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 125why, one step back125 @click.argument("input", type=click.Path(dir_okay=False, allow_dash=True))Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 126–128why, one step back126 def foo(input):127 click.echo(input)128Merge branch '7.x'David Lordbefore adoption7239794
lines 129–130why, one step back129 result = runner.invoke(foo, ["-"])130 assert result.output == "-\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 131–135why, one step back131 assert result.exit_code == 0132133134def test_file_atomics(runner):135 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 136why, one step back136 @click.argument("output", type=click.File("wb", atomic=True))Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 137why, one step back137 def inout(output):Merge branch '7.x'David Lordbefore adoption7239794
line 138why, one step back138 output.write(b"Foo bar baz\n")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 139why, one step back139 output.flush()Merge branch '7.x'David Lordbefore adoption7239794
line 140why, one step back140 with open(output.name, "rb") as f:Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 141why, one step back141 old_content = f.read()Merge branch '7.x'David Lordbefore adoption7239794
line 142why, one step back142 assert old_content == b"OLD\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 143–144why, one step back143144 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 145–148why, one step back145 with open("foo.txt", "wb") as f:146 f.write(b"OLD\n")147 result = runner.invoke(inout, ["foo.txt"], input="Hey!", catch_exceptions=False)148 assert result.output == ""Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 149why, one step back149 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 150–151why, one step back150 with open("foo.txt", "rb") as f:151 assert f.read() == b"Foo bar baz\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 152–155why, one step back152153154def test_stdout_default(runner):155 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 156why, one step back156 @click.argument("output", type=click.File("w"), default="-")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 157why, one step back157 def inout(output):Merge branch '7.x'David Lordbefore adoption7239794
line 158why, one step back158 output.write("Foo bar baz\n")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 159–162why, one step back159 output.flush()160161 result = runner.invoke(inout, [])162 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 163why, one step back163 assert result.output == "Foo bar baz\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 164–165why, one step back164165Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
line 166why, one step back166@pytest.mark.parametrize(Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 167why, one step back167 ("nargs", "value", "expect"),Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
line 168why, one step back168 [Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
lines 169–174why, one step back169 (2, "", None),170 (2, "a", "Argument 'arg' takes 2 values but 1 was given."),171 (2, "a b", ("a", "b")),172 (2, "a b c", "Argument 'arg' takes 2 values but 3 were given."),173 (-1, "a b c", ("a", "b", "c")),174 (-1, "", ()),Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
lines 175–176why, one step back175 ],176)Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 177why, one step back177def test_nargs_envvar(runner, nargs, value, expect):Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
lines 178–181why, one step back178 if nargs == -1:179 param = click.argument("arg", envvar="X", nargs=nargs)180 else:181 param = click.option("--arg", envvar="X", nargs=nargs)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 182–183why, one step back182183 @click.command()Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
line 184why, one step back184 @paramMerge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 185why, one step back185 def cmd(arg):Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 186why, one step back186 return argMerge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 187why, one step back187Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
lines 188–193why, one step back188 result = runner.invoke(cmd, env={"X": value}, standalone_mode=False)189190 if isinstance(expect, str):191 assert expect in str(result.exception)192 else:193 assert result.return_value == expectMerge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 194–197why, one step back194195196def test_empty_nargs(runner):197 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 198why, one step back198 @click.argument("arg", nargs=-1)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 199why, one step back199 def cmd(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 200why, one step back200 click.echo(f"arg:{'|'.join(arg)}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 201–203why, one step back201202 result = runner.invoke(cmd, [])203 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 204why, one step back204 assert result.output == "arg:\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 205–206why, one step back205206 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 207why, one step back207 @click.argument("arg", nargs=-1, required=True)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 208why, one step back208 def cmd2(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 209why, one step back209 click.echo(f"arg:{'|'.join(arg)}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 210–212why, one step back210211 result = runner.invoke(cmd2, [])212 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 213why, one step back213 assert "Missing argument 'ARG...'" in result.outputMerge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 214–217why, one step back214215216def test_missing_arg(runner):217 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 218why, one step back218 @click.argument("arg")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 219why, one step back219 def cmd(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 220why, one step back220 click.echo(f"arg:{arg}")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 221–223why, one step back221222 result = runner.invoke(cmd, [])223 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 224why, one step back224 assert "Missing argument 'ARG'." in result.outputMerge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 225–226why, one step back225226Merge branch '7.x'David Lordbefore adoption2269786
lines 227–235why, one step back227def test_missing_argument_string_cast():228 ctx = click.Context(click.Command(""))229230 with pytest.raises(click.MissingParameter) as excinfo:231 click.Argument(["a"], required=True).full_process_value(ctx, None)232233 assert str(excinfo.value) == "missing parameter: a"234235Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 236–237why, one step back236def test_implicit_non_required(runner):237 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 238why, one step back238 @click.argument("f", default="test")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 239–243why, one step back239 def cli(f):240 click.echo(f)241242 result = runner.invoke(cli, [])243 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 244why, one step back244 assert result.output == "test\n"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 245–248why, one step back245246247def test_eat_options(runner):248 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 249–250why, one step back249 @click.option("-f")250 @click.argument("files", nargs=-1)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 251–255why, one step back251 def cmd(f, files):252 for filename in files:253 click.echo(filename)254 click.echo(f)255Merge branch '7.x'David Lordbefore adoption7239794
lines 256–257why, one step back256 result = runner.invoke(cmd, ["--", "-foo", "bar"])257 assert result.output.splitlines() == ["-foo", "bar", ""]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 258why, one step back258Merge branch '7.x'David Lordbefore adoption7239794
lines 259–260why, one step back259 result = runner.invoke(cmd, ["-f", "-x", "--", "-foo", "bar"])260 assert result.output.splitlines() == ["-foo", "bar", "-x"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 261–264why, one step back261262263def test_nargs_star_ordering(runner):264 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 265–267why, one step back265 @click.argument("a", nargs=-1)266 @click.argument("b")267 @click.argument("c")Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 268–271why, one step back268 def cmd(a, b, c):269 for arg in (a, b, c):270 click.echo(arg)271Merge branch '7.x'David Lordbefore adoption7239794
line 272why, one step back272 result = runner.invoke(cmd, ["a", "b", "c"])Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 273why, one step back273 assert result.output.splitlines() == ["('a',)", "b", "c"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 274–277why, one step back274275276def test_nargs_specified_plus_star_ordering(runner):277 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 278–280why, one step back278 @click.argument("a", nargs=-1)279 @click.argument("b")280 @click.argument("c", nargs=2)Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 281–284why, one step back281 def cmd(a, b, c):282 for arg in (a, b, c):283 click.echo(arg)284Merge branch '7.x'David Lordbefore adoption7239794
line 285why, one step back285 result = runner.invoke(cmd, ["a", "b", "c", "d", "e", "f"])Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 286why, one step back286 assert result.output.splitlines() == ["('a', 'b', 'c')", "d", "('e', 'f')"]Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 287–290why, one step back287288289def test_defaults_for_nargs(runner):290 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 291why, one step back291 @click.argument("a", nargs=2, type=int, default=(1, 2))Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
lines 292–296why, one step back292 def cmd(a):293 x, y = a294 click.echo(x + y)295296 result = runner.invoke(cmd, [])Merge branch '7.x'David Lordbefore adoption7239794
line 297why, one step back297 assert result.output.strip() == "3"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 298why, one step back298Merge branch '7.x'David Lordbefore adoption7239794
lines 299–300why, one step back299 result = runner.invoke(cmd, ["3", "4"])300 assert result.output.strip() == "7"Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 301why, one step back301Merge branch '7.x'David Lordbefore adoption7239794
line 302why, one step back302 result = runner.invoke(cmd, ["3"])Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986
line 303why, one step back303 assert result.exception is not NoneMerge branch '7.x'David Lordbefore adoption7239794
line 304why, one step back304 assert "argument a takes 2 values" in result.outputMerge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523
lines 305–308why, one step back305306307def test_multiple_param_decls_not_allowed(runner):308 with pytest.raises(TypeError):Merge branch '7.x'David Lordbefore adoption7239794
line 309why, one step back309Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523
line 310why, one step back310 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 311why, one step back311 @click.argument("x", click.Choice(["a", "b"]))Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523
lines 312–313why, one step back312 def copy(x):313 click.echo(x)Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854
lines 314–333why, one step back314315316@pytest.mark.parametrize(317 ("value", "code", "output"),318 [319 ((), 2, "Argument 'arg' takes 2 values but 0 were given."),320 (("a",), 2, "Argument 'arg' takes 2 values but 1 was given."),321 (("a", "b"), 0, "len 2"),322 (("a", "b", "c"), 2, "Argument 'arg' takes 2 values but 3 were given."),323 ],324)325def test_nargs_default(runner, value, code, output):326 @click.command()327 @click.argument("arg", nargs=2, default=value)328 def cmd(arg):329 click.echo(f"len {len(arg)}")330331 result = runner.invoke(cmd)332 assert result.exit_code == code333 assert output in result.outputMerge pull request #1614 from MLH-Fellowship/help-sypnosisDavid Lordbefore adoption2dafcfd
lines 334–374why, one step back334335336def test_subcommand_help(runner):337 @click.group()338 @click.argument("name")339 @click.argument("val")340 @click.option("--opt")341 @click.pass_context342 def cli(ctx, name, val, opt):343 ctx.obj = dict(name=name, val=val)344345 @cli.command()346 @click.pass_obj347 def cmd(obj):348 click.echo(f"CMD for {obj['name']} with value {obj['val']}")349350 result = runner.invoke(cli, ["foo", "bar", "cmd", "--help"])351 assert not result.exception352 assert "Usage: cli NAME VAL cmd [OPTIONS]" in result.output353354355def test_nested_subcommand_help(runner):356 @click.group()357 @click.argument("arg1")358 @click.option("--opt1")359 def cli(arg1, opt1):360 pass361362 @cli.group()363 @click.argument("arg2")364 @click.option("--opt2")365 def cmd(arg2, opt2):366 pass367368 @cmd.command()369 def subcmd():370 click.echo("subcommand")371372 result = runner.invoke(cli, ["arg1", "cmd", "arg2", "subcmd", "--help"])373 assert not result.exception374 assert "Usage: cli ARG1 cmd ARG2 subcmd [OPTIONS]" in result.output