Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

534 lines · 14.6 KiB · Python

Last changed by

Merge pull request #1405 from energizah/commands-listDavid Lordbefore adoption7147f41

History of this file

Take it

The walk stopped after 200 commits: lines older than 9db53b9 point at it.

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 1–2why, one step back
1import os
2import uuid

Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455

line 3why, one step back
3from itertools import chain

Merge branch '7.x'David Lordbefore adoption7239794

line 4why, one step back
4

Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455

lines 5–6why, one step back
5import pytest
6

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 7–13why, one step back
7import click
8910def test_basic_functionality(runner):11 @click.command()12 def cli():13 """Hello World!"""

Merge branch '7.x'David Lordbefore adoption7239794

line 14why, one step back
14 click.echo("I EXECUTED")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 15why, one step back
15

Merge branch '7.x'David Lordbefore adoption7239794

line 16why, one step back
16 result = runner.invoke(cli, ["--help"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 18–19why, one step back
18 assert "Hello World!" in result.output
19 assert "Show this message and exit." in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 20why, one step back
20 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 21why, one step back
21 assert "I EXECUTED" not in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 22–24why, one step back
22
23 result = runner.invoke(cli, [])24 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 25why, one step back
25 assert "I EXECUTED" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 26–28why, one step back
26 assert result.exit_code == 0
2728

Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a

lines 29–41why, one step back
29def test_repr():
30 @click.command()31 def command():32 pass3334 @click.group()35 def group():36 pass3738 @group.command()39 def subcommand():40 pass41

Merge branch '7.x'David Lordbefore adoption7239794

lines 42–44why, one step back
42 assert repr(command) == "<Command command>"
43 assert repr(group) == "<Group group>"44 assert repr(subcommand) == "<Command subcommand>"

Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a

lines 45–46why, one step back
45
46

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 47–51why, one step back
47def test_return_values():
48 @click.command()49 def cli():50 return 4251

Merge branch '7.x'David Lordbefore adoption7239794

line 52why, one step back
52 with cli.make_context("foo", []) as ctx:

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 53why, one step back
53 rv = cli.invoke(ctx)

Merge pull request #1445 from tirkarthi/fix-syntax-warningJoshua Bronsonbefore adoption6c454c8

line 54why, one step back
54 assert rv == 42

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 55–60why, one step back
55
5657def test_basic_group(runner):58 @click.group()59 def cli():60 """This is the root."""

Merge branch '7.x'David Lordbefore adoption7239794

line 61why, one step back
61 click.echo("ROOT EXECUTED")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 62–65why, one step back
62
63 @cli.command()64 def subcommand():65 """This is a subcommand."""

Merge branch '7.x'David Lordbefore adoption7239794

line 66why, one step back
66 click.echo("SUBCOMMAND EXECUTED")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 67why, one step back
67

Merge branch '7.x'David Lordbefore adoption7239794

line 68why, one step back
68 result = runner.invoke(cli, ["--help"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 70–72why, one step back
70 assert "COMMAND [ARGS]..." in result.output
71 assert "This is the root" in result.output72 assert "This is a subcommand." in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 73why, one step back
73 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 74why, one step back
74 assert "ROOT EXECUTED" not in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 75why, one step back
75

Merge branch '7.x'David Lordbefore adoption7239794

line 76why, one step back
76 result = runner.invoke(cli, ["subcommand"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 77–78why, one step back
77 assert not result.exception
78 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

lines 79–80why, one step back
79 assert "ROOT EXECUTED" in result.output
80 assert "SUBCOMMAND EXECUTED" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 81–82why, one step back
81
82

Merge pull request #1405 from energizah/commands-listDavid Lordbefore adoption7147f41

lines 83–106why, one step back
83def test_group_commands_dict(runner):
84 """A Group can be built with a dict of commands."""8586 @click.command()87 def sub():88 click.echo("sub", nl=False)8990 cli = click.Group(commands={"other": sub})91 result = runner.invoke(cli, ["other"])92 assert result.output == "sub"939495def test_group_from_list(runner):96 """A Group can be built with a list of commands."""9798 @click.command()99 def sub():100 click.echo("sub", nl=False)101102 cli = click.Group(commands=[sub])103 result = runner.invoke(cli, ["sub"])104 assert result.output == "sub"105106

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 107–108why, one step back
107def test_basic_option(runner):
108 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 109why, one step back
109 @click.option("--foo", default="no value")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 110why, one step back
110 def cli(foo):

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

line 111why, one step back
111 click.echo(f"FOO:[{foo}]")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 112–114why, one step back
112
113 result = runner.invoke(cli, [])114 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 115why, one step back
115 assert "FOO:[no value]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 116why, one step back
116

Merge branch '7.x'David Lordbefore adoption7239794

line 117why, one step back
117 result = runner.invoke(cli, ["--foo=42"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 119why, one step back
119 assert "FOO:[42]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 120why, one step back
120

Merge branch '7.x'David Lordbefore adoption7239794

line 121why, one step back
121 result = runner.invoke(cli, ["--foo"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 122why, one step back
122 assert result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 123why, one step back
123 assert "--foo option requires an argument" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 124why, one step back
124

Merge branch '7.x'David Lordbefore adoption7239794

line 125why, one step back
125 result = runner.invoke(cli, ["--foo="])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 127why, one step back
127 assert "FOO:[]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 128why, one step back
128

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

line 129why, one step back
129 result = runner.invoke(cli, ["--foo=\N{SNOWMAN}"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

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

line 131why, one step back
131 assert "FOO:[\N{SNOWMAN}]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 132–135why, one step back
132
133134def test_int_option(runner):135 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 136why, one step back
136 @click.option("--foo", default=42)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 137why, one step back
137 def cli(foo):

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

line 138why, one step back
138 click.echo(f"FOO:[{foo * 2}]")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 139–141why, one step back
139
140 result = runner.invoke(cli, [])141 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 142why, one step back
142 assert "FOO:[84]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 143why, one step back
143

Merge branch '7.x'David Lordbefore adoption7239794

line 144why, one step back
144 result = runner.invoke(cli, ["--foo=23"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 146why, one step back
146 assert "FOO:[46]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 147why, one step back
147

Merge branch '7.x'David Lordbefore adoption7239794

line 148why, one step back
148 result = runner.invoke(cli, ["--foo=bar"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 149why, one step back
149 assert result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 150why, one step back
150 assert "Invalid value for '--foo': bar is not a valid integer" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 151–154why, one step back
151
152153def test_uuid_option(runner):154 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 155–157why, one step back
155 @click.option(
156 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID157 )

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 158–159why, one step back
158 def cli(u):
159 assert type(u) is uuid.UUID

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

line 160why, one step back
160 click.echo(f"U:[{u}]")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 161–163why, one step back
161
162 result = runner.invoke(cli, [])163 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 164why, one step back
164 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 165why, one step back
165

Merge branch '7.x'David Lordbefore adoption7239794

line 166why, one step back
166 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 168why, one step back
168 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 169why, one step back
169

Merge branch '7.x'David Lordbefore adoption7239794

line 170why, one step back
170 result = runner.invoke(cli, ["--u=bar"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 171why, one step back
171 assert result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 172why, one step back
172 assert "Invalid value for '--u': bar is not a valid UUID value" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 173–176why, one step back
173
174175def test_float_option(runner):176 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 177why, one step back
177 @click.option("--foo", default=42, type=click.FLOAT)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 178–179why, one step back
178 def cli(foo):
179 assert type(foo) is float

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

line 180why, one step back
180 click.echo(f"FOO:[{foo}]")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 181–183why, one step back
181
182 result = runner.invoke(cli, [])183 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 184why, one step back
184 assert "FOO:[42.0]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 185why, one step back
185

Merge branch '7.x'David Lordbefore adoption7239794

line 186why, one step back
186 result = runner.invoke(cli, ["--foo=23.5"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 188why, one step back
188 assert "FOO:[23.5]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 189why, one step back
189

Merge branch '7.x'David Lordbefore adoption7239794

line 190why, one step back
190 result = runner.invoke(cli, ["--foo=bar"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 191why, one step back
191 assert result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 192why, one step back
192 assert "Invalid value for '--foo': bar is not a valid float" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 193–196why, one step back
193
194195def test_boolean_option(runner):196 for default in True, False:

Merge branch '7.x'David Lordbefore adoption7239794

line 197why, one step back
197

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 199why, one step back
199 @click.option("--with-foo/--without-foo", default=default)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 200–202why, one step back
200 def cli(with_foo):
201 click.echo(with_foo)202

Merge branch '7.x'David Lordbefore adoption7239794

line 203why, one step back
203 result = runner.invoke(cli, ["--with-foo"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 205–206why, one step back
205 assert result.output == "True\n"
206 result = runner.invoke(cli, ["--without-foo"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 208why, one step back
208 assert result.output == "False\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 209–210why, one step back
209 result = runner.invoke(cli, [])
210 assert not result.exception

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

line 211why, one step back
211 assert result.output == f"{default}\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 212–213why, one step back
212
213 for default in True, False:

Merge branch '7.x'David Lordbefore adoption7239794

line 214why, one step back
214

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 216why, one step back
216 @click.option("--flag", is_flag=True, default=default)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 217–219why, one step back
217 def cli(flag):
218 click.echo(flag)219

Merge branch '7.x'David Lordbefore adoption7239794

line 220why, one step back
220 result = runner.invoke(cli, ["--flag"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

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

line 222why, one step back
222 assert result.output == f"{not default}\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 223–224why, one step back
223 result = runner.invoke(cli, [])
224 assert not result.exception

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

line 225why, one step back
225 assert result.output == f"{default}\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 226–227why, one step back
226
227

Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455

lines 228–239why, one step back
228@pytest.mark.parametrize(
229 ("value", "expect"),230 chain(231 ((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),232 ((x, "False") for x in ("0", "false", "f", "no", "n", "off")),233 ),234)235def test_boolean_conversion(runner, value, expect):236 @click.command()237 @click.option("--flag", type=bool)238 def cli(flag):239 click.echo(flag, nl=False)

Merge branch '7.x'David Lordbefore adoption7239794

line 240why, one step back
240

Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455

lines 241–242why, one step back
241 result = runner.invoke(cli, ["--flag", value])
242 assert result.output == expect

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 243why, one step back
243

Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455

lines 244–245why, one step back
244 result = runner.invoke(cli, ["--flag", value.title()])
245 assert result.output == expect

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

line 250why, one step back
250 @click.option("--file", type=click.File("w"))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 251why, one step back
251 def input(file):

Merge branch '7.x'David Lordbefore adoption7239794

line 252why, one step back
252 file.write("Hello World!\n")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 253–254why, one step back
253
254 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 255why, one step back
255 @click.option("--file", type=click.File("r"))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 256–259why, one step back
256 def output(file):
257 click.echo(file.read())258259 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

lines 260–261why, one step back
260 result_in = runner.invoke(input, ["--file=example.txt"])
261 result_out = runner.invoke(output, ["--file=example.txt"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 262–263why, one step back
262
263 assert not result_in.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 264why, one step back
264 assert result_in.output == ""

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 265why, one step back
265 assert not result_out.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 266why, one step back
266 assert result_out.output == "Hello World!\n\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 267–272why, one step back
267
268269def test_file_lazy_mode(runner):270 do_io = False271272 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 273why, one step back
273 @click.option("--file", type=click.File("w"))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 274–275why, one step back
274 def input(file):
275 if do_io:

Merge branch '7.x'David Lordbefore adoption7239794

line 276why, one step back
276 file.write("Hello World!\n")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 277–278why, one step back
277
278 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 279why, one step back
279 @click.option("--file", type=click.File("r"))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 280–283why, one step back
280 def output(file):
281 pass282283 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

line 284why, one step back
284 os.mkdir("example.txt")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 285–286why, one step back
285
286 do_io = True

Merge branch '7.x'David Lordbefore adoption7239794

line 287why, one step back
287 result_in = runner.invoke(input, ["--file=example.txt"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 288–290why, one step back
288 assert result_in.exit_code == 1
289290 do_io = False

Merge branch '7.x'David Lordbefore adoption7239794

line 291why, one step back
291 result_in = runner.invoke(input, ["--file=example.txt"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 292–293why, one step back
292 assert result_in.exit_code == 0
293

Merge branch '7.x'David Lordbefore adoption7239794

line 294why, one step back
294 result_out = runner.invoke(output, ["--file=example.txt"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 295–297why, one step back
295 assert result_out.exception
296297 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 298why, one step back
298 @click.option("--file", type=click.File("w", lazy=False))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 299why, one step back
299 def input_non_lazy(file):

Merge branch '7.x'David Lordbefore adoption7239794

line 300why, one step back
300 file.write("Hello World!\n")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 301–302why, one step back
301
302 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

lines 303–304why, one step back
303 os.mkdir("example.txt")
304 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 305why, one step back
305 assert result_in.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

lines 306–307why, one step back
306 assert (
307 "Invalid value for '--file': Could not open file: example.txt"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 308why, one step back
308 in result_in.output

Merge branch '7.x'David Lordbefore adoption7239794

line 309why, one step back
309 )

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 310–313why, one step back
310
311312def test_path_option(runner):313 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 314why, one step back
314 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 315why, one step back
315 def write_to_dir(o):

Merge branch '7.x'David Lordbefore adoption7239794

lines 316–317why, one step back
316 with open(os.path.join(o, "foo.txt"), "wb") as f:
317 f.write(b"meh\n")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 318–319why, one step back
318
319 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

line 320why, one step back
320 os.mkdir("test")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 321why, one step back
321

Merge branch '7.x'David Lordbefore adoption7239794

line 322why, one step back
322 result = runner.invoke(write_to_dir, ["-O", "test"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 323–324why, one step back
323 assert not result.exception
324

Merge branch '7.x'David Lordbefore adoption7239794

lines 325–326why, one step back
325 with open("test/foo.txt", "rb") as f:
326 assert f.read() == b"meh\n"

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 327why, one step back
327

Merge branch '7.x'David Lordbefore adoption7239794

lines 328–329why, one step back
328 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])
329 assert "is a file" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 330–331why, one step back
330
331 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 332why, one step back
332 @click.option("-f", type=click.Path(exists=True))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 333why, one step back
333 def showtype(f):

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

lines 334–335why, one step back
334 click.echo(f"is_file={os.path.isfile(f)}")
335 click.echo(f"is_dir={os.path.isdir(f)}")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 336–337why, one step back
336
337 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

lines 338–339why, one step back
338 result = runner.invoke(showtype, ["-f", "xxx"])
339 assert "does not exist" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 340why, one step back
340

Merge branch '7.x'David Lordbefore adoption7239794

lines 341–343why, one step back
341 result = runner.invoke(showtype, ["-f", "."])
342 assert "is_file=False" in result.output343 assert "is_dir=True" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 344–345why, one step back
344
345 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 346why, one step back
346 @click.option("-f", type=click.Path())

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 347why, one step back
347 def exists(f):

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

line 348why, one step back
348 click.echo(f"exists={os.path.exists(f)}")

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 349–350why, one step back
349
350 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

lines 351–352why, one step back
351 result = runner.invoke(exists, ["-f", "xxx"])
352 assert "exists=False" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 353why, one step back
353

Merge branch '7.x'David Lordbefore adoption7239794

lines 354–355why, one step back
354 result = runner.invoke(exists, ["-f", "."])
355 assert "exists=True" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 356–359why, one step back
356
357358def test_choice_option(runner):359 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 360why, one step back
360 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 361–363why, one step back
361 def cli(method):
362 click.echo(method)363

Merge branch '7.x'David Lordbefore adoption7239794

line 364why, one step back
364 result = runner.invoke(cli, ["--method=foo"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 367why, one step back
367

Merge branch '7.x'David Lordbefore adoption7239794

line 368why, one step back
368 result = runner.invoke(cli, ["--method=meh"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 370–373why, one step back
370 assert (
371 "Invalid value for '--method': invalid choice: meh."372 " (choose from foo, bar, baz)" in result.output373 )

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 374why, one step back
374

Merge branch '7.x'David Lordbefore adoption7239794

lines 375–376why, one step back
375 result = runner.invoke(cli, ["--help"])
376 assert "--method [foo|bar|baz]" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 377–378why, one step back
377
378

Merge pull request #1273 from 0xDEC0DE/issue/1272David Lordbefore adoptiond15f740

lines 379–399why, one step back
379def test_choice_argument(runner):
380 @click.command()381 @click.argument("method", type=click.Choice(["foo", "bar", "baz"]))382 def cli(method):383 click.echo(method)384385 result = runner.invoke(cli, ["foo"])386 assert not result.exception387 assert result.output == "foo\n"388389 result = runner.invoke(cli, ["meh"])390 assert result.exit_code == 2391 assert (392 "Invalid value for '{foo|bar|baz}': invalid choice: meh. "393 "(choose from foo, bar, baz)" in result.output394 )395396 result = runner.invoke(cli, ["--help"])397 assert "{foo|bar|baz}" in result.output398399

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

lines 400–401why, one step back
400def test_datetime_option_default(runner):
401 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 402why, one step back
402 @click.option("--start_date", type=click.DateTime())

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 403why, one step back
403 def cli(start_date):

Merge branch '7.x'David Lordbefore adoption7239794

line 404why, one step back
404 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 405why, one step back
405

Merge branch '7.x'David Lordbefore adoption7239794

line 406why, one step back
406 result = runner.invoke(cli, ["--start_date=2015-09-29"])

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

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

Merge branch '7.x'David Lordbefore adoption7239794

line 408why, one step back
408 assert result.output == "2015-09-29T00:00:00\n"

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 409why, one step back
409

Merge branch '7.x'David Lordbefore adoption7239794

line 410why, one step back
410 result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

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

Merge branch '7.x'David Lordbefore adoption7239794

line 412why, one step back
412 assert result.output == "2015-09-29T09:11:22\n"

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 413why, one step back
413

Merge branch '7.x'David Lordbefore adoption7239794

line 414why, one step back
414 result = runner.invoke(cli, ["--start_date=2015-09"])

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 416–420why, one step back
416 assert (
417 "Invalid value for '--start_date':"418 " invalid datetime format: 2015-09."419 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"420 ) in result.output

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 421why, one step back
421

Merge branch '7.x'David Lordbefore adoption7239794

lines 422–425why, one step back
422 result = runner.invoke(cli, ["--help"])
423 assert (424 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output425 )

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

lines 426–429why, one step back
426
427428def test_datetime_option_custom(runner):429 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 430why, one step back
430 @click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 431why, one step back
431 def cli(start_date):

Merge branch '7.x'David Lordbefore adoption7239794

line 432why, one step back
432 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

line 433why, one step back
433

Merge branch '7.x'David Lordbefore adoption7239794

line 434why, one step back
434 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

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

Merge branch '7.x'David Lordbefore adoption7239794

line 436why, one step back
436 assert result.output == "2010-06-05T00:00:00\n"

Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

lines 437–438why, one step back
437
438

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 439–440why, one step back
439def test_required_option(runner):
440 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 441why, one step back
441 @click.option("--foo", required=True)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 442–446why, one step back
442 def cli(foo):
443 click.echo(foo)444445 result = runner.invoke(cli, [])446 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

line 447why, one step back
447 assert "Missing option '--foo'" in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 448–457why, one step back
448
449450def test_evaluation_order(runner):451 called = []452453 def memo(ctx, param, value):454 called.append(value)455 return value456457 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 458–464why, one step back
458 @click.option("--missing", default="missing", is_eager=False, callback=memo)
459 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)460 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)461 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)462 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)463 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)464 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 465–467why, one step back
465 def cli(**x):
466 pass467

Merge branch '7.x'David Lordbefore adoption7239794

lines 468–480why, one step back
468 result = runner.invoke(
469 cli,470 [471 "--eager-flag2",472 "--eager-flag1",473 "--normal-flag2",474 "--eager-flag3",475 "--normal-flag3",476 "--normal-flag3",477 "--normal-flag1",478 "--normal-flag1",479 ],480 )

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 481–482why, one step back
481 assert not result.exception
482 assert called == [

Merge branch '7.x'David Lordbefore adoption7239794

lines 483–489why, one step back
483 "eager2",
484 "eager1",485 "eager3",486 "normal2",487 "normal3",488 "normal1",489 "missing",

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 490–494why, one step back
490 ]
491492493def test_hidden_option(runner):494 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 495why, one step back
495 @click.option("--nope", hidden=True)

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 496–498why, one step back
496 def cli(nope):
497 click.echo(nope)498

Merge branch '7.x'David Lordbefore adoption7239794

line 499why, one step back
499 result = runner.invoke(cli, ["--help"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 500why, one step back
500 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 501why, one step back
501 assert "--nope" not in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 502–512why, one step back
502
503504def test_hidden_command(runner):505 @click.group()506 def cli():507 pass508509 @cli.command(hidden=True)510 def nope():511 pass512

Merge branch '7.x'David Lordbefore adoption7239794

line 513why, one step back
513 result = runner.invoke(cli, ["--help"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 514why, one step back
514 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

line 515why, one step back
515 assert "nope" not in result.output

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

lines 516–530why, one step back
516
517518def test_hidden_group(runner):519 @click.group()520 def cli():521 pass522523 @cli.group(hidden=True)524 def subgroup():525 pass526527 @subgroup.command()528 def nope():529 pass530

Merge branch '7.x'David Lordbefore adoption7239794

line 531why, one step back
531 result = runner.invoke(cli, ["--help"])

Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9

line 532why, one step back
532 assert result.exit_code == 0

Merge branch '7.x'David Lordbefore adoption7239794

lines 533–534why, one step back
533 assert "subgroup" not in result.output
534 assert "nope" not in result.output