Skip to content
Myr

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 file

Take 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 back
1import sys
2

Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523

line 3why, one step back
3import pytest

Merge branch '7.x'David Lordbefore adoption7239794

line 4why, one step back
4

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 5–9why, one step back
5import click
678def test_nargs_star(runner):9 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 10–11why, one step back
10 @click.argument("src", nargs=-1)
11 @click.argument("dst")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 12why, one step back
12 def copy(src, dst):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

lines 13–14why, one step back
13 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 back
15

Merge branch '7.x'David Lordbefore adoption7239794

line 16why, one step back
16 result = runner.invoke(copy, ["foo.txt", "bar.txt", "dir"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 17why, one step back
17 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 18why, one step back
18 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 back
19
20

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

line 21why, one step back
21def test_argument_unbounded_nargs_cant_have_default(runner):

Merge branch '7.x'David Lordbefore adoption7239794

lines 22–23why, one step back
22 with pytest.raises(TypeError, match="nargs=-1"):
23

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 24why, one step back
24 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 25why, one step back
25 @click.argument("src", nargs=-1, default=42)

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 26–31why, one step back
26 def copy(src):
27 pass282930def test_nargs_tup(runner):31 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 32–33why, one step back
32 @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 back
34 def copy(name, point):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

lines 35–37why, one step back
35 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 back
38

Merge branch '7.x'David Lordbefore adoption7239794

line 39why, one step back
39 result = runner.invoke(copy, ["peter", "1", "2"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 40why, one step back
40 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 41why, one step back
41 assert result.output.splitlines() == ["name=peter", "point=1/2"]

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 42–52why, one step back
42
4344def 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 back
53

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 54why, one step back
54 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 55why, one step back
55 @click.argument("item", **opts)

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 56why, one step back
56 def copy(item):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

lines 57–58why, one step back
57 name, id = item
58 click.echo(f"name={name} id={id:d}")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 59why, one step back
59

Merge branch '7.x'David Lordbefore adoption7239794

line 60why, one step back
60 result = runner.invoke(copy, ["peter", "1"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 61why, one step back
61 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 62why, one step back
62 assert result.output.splitlines() == ["name=peter id=1"]

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 63–66why, one step back
63
6465def test_nargs_err(runner):66 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 67why, one step back
67 @click.argument("x")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 68–70why, one step back
68 def copy(x):
69 click.echo(x)70

Merge branch '7.x'David Lordbefore adoption7239794

line 71why, one step back
71 result = runner.invoke(copy, ["foo"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 72why, one step back
72 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 73why, one step back
73 assert result.output == "foo\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 74why, one step back
74

Merge branch '7.x'David Lordbefore adoption7239794

line 75why, one step back
75 result = runner.invoke(copy, ["foo", "bar"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 76why, one step back
76 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

line 77why, one step back
77 assert "Got unexpected extra argument (bar)" in result.output

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 78–81why, one step back
78
7980def test_bytes_args(runner, monkeypatch):81 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 82why, one step back
82 @click.argument("arg")

Merge branch '7.x'David Lordbefore adoption8f36eab

line 83why, one step back
83 def from_bytes(arg):

Merge branch '7.x'David Lordbefore adoption7239794

line 84why, one step back
84 assert isinstance(

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 85why, one step back
85 arg, str

Merge branch '7.x'David Lordbefore adoption7239794

line 86why, one step back
86 ), "UTF-8 encoded argument should be implicitly converted to Unicode"

Merge branch '7.x'David Lordbefore adoption8f36eab

lines 87–88why, one step back
87
88 # Simulate empty locale environment variables

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

lines 89–91why, one step back
89 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 back
92

Merge branch '7.x'David Lordbefore adoption7239794

lines 93–94why, one step back
93 runner.invoke(
94 from_bytes,

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 95why, one step back
95 ["Something outside of ASCII range: 林".encode()],

Merge branch '7.x'David Lordbefore adoption7239794

lines 96–97why, one step back
96 catch_exceptions=False,
97 )

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 98–101why, one step back
98
99100def test_file_args(runner):101 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 102–103why, one step back
102 @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 back
104 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 back
112 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 back
114 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

lines 115–116why, one step back
115 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 back
117

Merge branch '7.x'David Lordbefore adoption7239794

lines 118–119why, one step back
118 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 back
120 assert result.exit_code == 0
121122123def test_path_args(runner):124 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 125why, one step back
125 @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 back
126 def foo(input):
127 click.echo(input)128

Merge branch '7.x'David Lordbefore adoption7239794

lines 129–130why, one step back
129 result = runner.invoke(foo, ["-"])
130 assert result.output == "-\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 131–135why, one step back
131 assert result.exit_code == 0
132133134def test_file_atomics(runner):135 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 136why, one step back
136 @click.argument("output", type=click.File("wb", atomic=True))

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 137why, one step back
137 def inout(output):

Merge branch '7.x'David Lordbefore adoption7239794

line 138why, one step back
138 output.write(b"Foo bar baz\n")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 139why, one step back
139 output.flush()

Merge branch '7.x'David Lordbefore adoption7239794

line 140why, one step back
140 with open(output.name, "rb") as f:

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 141why, one step back
141 old_content = f.read()

Merge branch '7.x'David Lordbefore adoption7239794

line 142why, one step back
142 assert old_content == b"OLD\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 143–144why, one step back
143
144 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

lines 145–148why, one step back
145 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 back
149 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

lines 150–151why, one step back
150 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 back
152
153154def test_stdout_default(runner):155 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 156why, one step back
156 @click.argument("output", type=click.File("w"), default="-")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 157why, one step back
157 def inout(output):

Merge branch '7.x'David Lordbefore adoption7239794

line 158why, one step back
158 output.write("Foo bar baz\n")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 159–162why, one step back
159 output.flush()
160161 result = runner.invoke(inout, [])162 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 163why, one step back
163 assert result.output == "Foo bar baz\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 164–165why, one step back
164
165

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

line 166why, one step back
166@pytest.mark.parametrize(

Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7

line 167why, one step back
167 ("nargs", "value", "expect"),

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

line 168why, one step back
168 [

Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7

lines 169–174why, one step back
169 (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 back
175 ],
176)

Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7

line 177why, one step back
177def test_nargs_envvar(runner, nargs, value, expect):

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

lines 178–181why, one step back
178 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 back
182
183 @click.command()

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

line 184why, one step back
184 @param

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 185why, one step back
185 def cmd(arg):

Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7

line 186why, one step back
186 return arg

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 187why, one step back
187

Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7

lines 188–193why, one step back
188 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 == expect

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 194–197why, one step back
194
195196def test_empty_nargs(runner):197 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 198why, one step back
198 @click.argument("arg", nargs=-1)

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 199why, one step back
199 def cmd(arg):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 200why, one step back
200 click.echo(f"arg:{'|'.join(arg)}")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 201–203why, one step back
201
202 result = runner.invoke(cmd, [])203 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 204why, one step back
204 assert result.output == "arg:\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 205–206why, one step back
205
206 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 207why, one step back
207 @click.argument("arg", nargs=-1, required=True)

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 208why, one step back
208 def cmd2(arg):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 209why, one step back
209 click.echo(f"arg:{'|'.join(arg)}")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 210–212why, one step back
210
211 result = runner.invoke(cmd2, [])212 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

line 213why, one step back
213 assert "Missing argument 'ARG...'" in result.output

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 214–217why, one step back
214
215216def test_missing_arg(runner):217 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 218why, one step back
218 @click.argument("arg")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 219why, one step back
219 def cmd(arg):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 220why, one step back
220 click.echo(f"arg:{arg}")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 221–223why, one step back
221
222 result = runner.invoke(cmd, [])223 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

line 224why, one step back
224 assert "Missing argument 'ARG'." in result.output

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 225–226why, one step back
225
226

Merge branch '7.x'David Lordbefore adoption2269786

lines 227–235why, one step back
227def 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"234235

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 236–237why, one step back
236def test_implicit_non_required(runner):
237 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 238why, one step back
238 @click.argument("f", default="test")

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 239–243why, one step back
239 def cli(f):
240 click.echo(f)241242 result = runner.invoke(cli, [])243 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 244why, one step back
244 assert result.output == "test\n"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 245–248why, one step back
245
246247def test_eat_options(runner):248 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 249–250why, one step back
249 @click.option("-f")
250 @click.argument("files", nargs=-1)

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 251–255why, one step back
251 def cmd(f, files):
252 for filename in files:253 click.echo(filename)254 click.echo(f)255

Merge branch '7.x'David Lordbefore adoption7239794

lines 256–257why, one step back
256 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 back
258

Merge branch '7.x'David Lordbefore adoption7239794

lines 259–260why, one step back
259 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 back
261
262263def test_nargs_star_ordering(runner):264 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 265–267why, one step back
265 @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 back
268 def cmd(a, b, c):
269 for arg in (a, b, c):270 click.echo(arg)271

Merge branch '7.x'David Lordbefore adoption7239794

line 272why, one step back
272 result = runner.invoke(cmd, ["a", "b", "c"])

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 273why, one step back
273 assert result.output.splitlines() == ["('a',)", "b", "c"]

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

lines 274–277why, one step back
274
275276def test_nargs_specified_plus_star_ordering(runner):277 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 278–280why, one step back
278 @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 back
281 def cmd(a, b, c):
282 for arg in (a, b, c):283 click.echo(arg)284

Merge branch '7.x'David Lordbefore adoption7239794

line 285why, one step back
285 result = runner.invoke(cmd, ["a", "b", "c", "d", "e", "f"])

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 286why, one step back
286 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 back
287
288289def test_defaults_for_nargs(runner):290 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 291why, one step back
291 @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 back
292 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 back
297 assert result.output.strip() == "3"

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 298why, one step back
298

Merge branch '7.x'David Lordbefore adoption7239794

lines 299–300why, one step back
299 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 back
301

Merge branch '7.x'David Lordbefore adoption7239794

line 302why, one step back
302 result = runner.invoke(cmd, ["3"])

Merge pull request #991 from dawran6/docs-#975Dan Sullybefore adoption43cb986

line 303why, one step back
303 assert result.exception is not None

Merge branch '7.x'David Lordbefore adoption7239794

line 304why, one step back
304 assert "argument a takes 2 values" in result.output

Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523

lines 305–308why, one step back
305
306307def test_multiple_param_decls_not_allowed(runner):308 with pytest.raises(TypeError):

Merge branch '7.x'David Lordbefore adoption7239794

line 309why, one step back
309

Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523

line 310why, one step back
310 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 311why, one step back
311 @click.argument("x", click.Choice(["a", "b"]))

Merge pull request #1014 from rhgrant10/feature/574David Lordbefore adoptionb0c7523

lines 312–313why, one step back
312 def copy(x):
313 click.echo(x)

Merge pull request #1604 from MLH-Fellowship/envvar-nargs-bugDavid Lordbefore adoption82ca854

lines 314–333why, one step back
314
315316@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.output

Merge pull request #1614 from MLH-Fellowship/help-sypnosisDavid Lordbefore adoption2dafcfd

lines 334–374why, one step back
334
335336def 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