Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

580 lines · 15.9 KiB · Python

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 55682f6 point at it.

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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")

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 15why, one step back
15

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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:

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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")

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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")

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 67why, one step back
67

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 75why, one step back
75

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 81–84why, one step back
81
8283def test_basic_option(runner):84 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 92why, one step back
92

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 96why, one step back
96

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 100why, one step back
100

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 104why, one step back
104

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 108–111why, one step back
108
109110def test_int_option(runner):111 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 119why, one step back
119

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 123why, one step back
123

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 127–130why, one step back
127
128129def test_uuid_option(runner):130 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 131–133why, one step back
131 @click.option(
132 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID133 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 141why, one step back
141

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 145why, one step back
145

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 149–152why, one step back
149
150151def test_float_option(runner):152 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 161why, one step back
161

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 165why, one step back
165

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 169–172why, one step back
169
170171def test_boolean_option(runner):172 for default in True, False:

Merge branch '7.x'David Lordbefore adoption7239794

line 173why, one step back
173

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 176–178why, one step back
176 def cli(with_foo):
177 click.echo(with_foo)178

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 188–189why, one step back
188
189 for default in True, False:

Merge branch '7.x'David Lordbefore adoption7239794

line 190why, one step back
190

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 193–195why, one step back
193 def cli(flag):
194 click.echo(flag)195

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 202–203why, one step back
202
203

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

lines 204–215why, one step back
204@pytest.mark.parametrize(
205 ("value", "expect"),206 chain(207 ((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),208 ((x, "False") for x in ("0", "false", "f", "no", "n", "off")),209 ),210)211def test_boolean_conversion(runner, value, expect):212 @click.command()213 @click.option("--flag", type=bool)214 def cli(flag):215 click.echo(flag, nl=False)

Merge branch '7.x'David Lordbefore adoption7239794

line 216why, one step back
216

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 219why, one step back
219

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 222–225why, one step back
222
223224def test_file_option(runner):225 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 229–230why, one step back
229
230 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 232–235why, one step back
232 def output(file):
233 click.echo(file.read())234235 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 238–239why, one step back
238
239 assert not result_in.exception

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 243–248why, one step back
243
244245def test_file_lazy_mode(runner):246 do_io = False247248 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 250–251why, one step back
250 def input(file):
251 if do_io:

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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"))

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 261–262why, one step back
261
262 do_io = True

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 264–266why, one step back
264 assert result_in.exit_code == 1
265266 do_io = False

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 268–269why, one step back
268 assert result_in.exit_code == 0
269

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 271–273why, one step back
271 assert result_out.exception
272273 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 277–278why, one step back
277
278 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 285why, one step back
285 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 294–295why, one step back
294
295 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 297why, one step back
297

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 299–300why, one step back
299 assert not result.exception
300

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 303why, one step back
303

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 306–307why, one step back
306
307 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 312–313why, one step back
312
313 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 316why, one step back
316

Merge branch '7.x'David Lordbefore adoption7239794

lines 317–319why, one step back
317 result = runner.invoke(showtype, ["-f", "."])
318 assert "is_file=False" in result.output319 assert "is_dir=True" in result.output

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 320–321why, one step back
320
321 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

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

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 325–326why, one step back
325
326 with runner.isolated_filesystem():

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 329why, one step back
329

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 332–335why, one step back
332
333334def test_choice_option(runner):335 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 337–339why, one step back
337 def cli(method):
338 click.echo(method)339

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 343why, one step back
343

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 346–349why, one step back
346 assert (
347 "Invalid value for '--method': invalid choice: meh."348 " (choose from foo, bar, baz)" in result.output349 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 350why, one step back
350

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 353–354why, one step back
353
354

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

lines 355–375why, one step back
355def test_choice_argument(runner):
356 @click.command()357 @click.argument("method", type=click.Choice(["foo", "bar", "baz"]))358 def cli(method):359 click.echo(method)360361 result = runner.invoke(cli, ["foo"])362 assert not result.exception363 assert result.output == "foo\n"364365 result = runner.invoke(cli, ["meh"])366 assert result.exit_code == 2367 assert (368 "Invalid value for '{foo|bar|baz}': invalid choice: meh. "369 "(choose from foo, bar, baz)" in result.output370 )371372 result = runner.invoke(cli, ["--help"])373 assert "{foo|bar|baz}" in result.output374375

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 381why, one step back
381

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 385why, one step back
385

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 389why, one step back
389

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 392–396why, one step back
392 assert (
393 "Invalid value for '--start_date':"394 " invalid datetime format: 2015-09."395 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"396 ) in result.output

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

line 397why, one step back
397

Merge branch '7.x'David Lordbefore adoption7239794

lines 398–401why, one step back
398 result = runner.invoke(cli, ["--help"])
399 assert (400 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output401 )

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

lines 402–405why, one step back
402
403404def test_datetime_option_custom(runner):405 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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=Wednesday June 05, 2010"])

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 == "2010-06-05T00:00:00\n"

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

lines 413–414why, one step back
413
414

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 415–416why, one step back
415def test_int_range_option(runner):
416 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 417why, one step back
417 @click.option("--x", type=click.IntRange(0, 5))

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 418–420why, one step back
418 def cli(x):
419 click.echo(x)420

Merge branch '7.x'David Lordbefore adoption7239794

line 421why, one step back
421 result = runner.invoke(cli, ["--x=5"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 423why, one step back
423 assert result.output == "5\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 424why, one step back
424

Merge branch '7.x'David Lordbefore adoption7239794

line 425why, one step back
425 result = runner.invoke(cli, ["--x=6"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 427–428why, one step back
427 assert (
428 "Invalid value for '--x': 6 is not in the valid range of 0 to 5.\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 429why, one step back
429 in result.output

Merge branch '7.x'David Lordbefore adoption7239794

line 430why, one step back
430 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 431–432why, one step back
431
432 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 433why, one step back
433 @click.option("--x", type=click.IntRange(0, 5, clamp=True))

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 434–436why, one step back
434 def clamp(x):
435 click.echo(x)436

Merge branch '7.x'David Lordbefore adoption7239794

line 437why, one step back
437 result = runner.invoke(clamp, ["--x=5"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 439why, one step back
439 assert result.output == "5\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 440why, one step back
440

Merge branch '7.x'David Lordbefore adoption7239794

line 441why, one step back
441 result = runner.invoke(clamp, ["--x=6"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 443why, one step back
443 assert result.output == "5\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 444why, one step back
444

Merge branch '7.x'David Lordbefore adoption7239794

line 445why, one step back
445 result = runner.invoke(clamp, ["--x=-1"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 447why, one step back
447 assert result.output == "0\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 448–451why, one step back
448
449450def test_float_range_option(runner):451 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 452why, one step back
452 @click.option("--x", type=click.FloatRange(0, 5))

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 453–455why, one step back
453 def cli(x):
454 click.echo(x)455

Merge branch '7.x'David Lordbefore adoption7239794

line 456why, one step back
456 result = runner.invoke(cli, ["--x=5.0"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 458why, one step back
458 assert result.output == "5.0\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 459why, one step back
459

Merge branch '7.x'David Lordbefore adoption7239794

line 460why, one step back
460 result = runner.invoke(cli, ["--x=6.0"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 462–463why, one step back
462 assert (
463 "Invalid value for '--x': 6.0 is not in the valid range of 0 to 5.\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 464why, one step back
464 in result.output

Merge branch '7.x'David Lordbefore adoption7239794

line 465why, one step back
465 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 466–467why, one step back
466
467 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

line 468why, one step back
468 @click.option("--x", type=click.FloatRange(0, 5, clamp=True))

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 469–471why, one step back
469 def clamp(x):
470 click.echo(x)471

Merge branch '7.x'David Lordbefore adoption7239794

line 472why, one step back
472 result = runner.invoke(clamp, ["--x=5.0"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 474why, one step back
474 assert result.output == "5.0\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 475why, one step back
475

Merge branch '7.x'David Lordbefore adoption7239794

line 476why, one step back
476 result = runner.invoke(clamp, ["--x=6.0"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 478why, one step back
478 assert result.output == "5\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 479why, one step back
479

Merge branch '7.x'David Lordbefore adoption7239794

line 480why, one step back
480 result = runner.invoke(clamp, ["--x=-1.0"])

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 482why, one step back
482 assert result.output == "0\n"

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 483–486why, one step back
483
484485def test_required_option(runner):486 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 488–492why, one step back
488 def cli(foo):
489 click.echo(foo)490491 result = runner.invoke(cli, [])492 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 494–503why, one step back
494
495496def test_evaluation_order(runner):497 called = []498499 def memo(ctx, param, value):500 called.append(value)501 return value502503 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 504–510why, one step back
504 @click.option("--missing", default="missing", is_eager=False, callback=memo)
505 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)506 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)507 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)508 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)509 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)510 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 511–513why, one step back
511 def cli(**x):
512 pass513

Merge branch '7.x'David Lordbefore adoption7239794

lines 514–526why, one step back
514 result = runner.invoke(
515 cli,516 [517 "--eager-flag2",518 "--eager-flag1",519 "--normal-flag2",520 "--eager-flag3",521 "--normal-flag3",522 "--normal-flag3",523 "--normal-flag1",524 "--normal-flag1",525 ],526 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 527–528why, one step back
527 assert not result.exception
528 assert called == [

Merge branch '7.x'David Lordbefore adoption7239794

lines 529–535why, one step back
529 "eager2",
530 "eager1",531 "eager3",532 "normal2",533 "normal3",534 "normal1",535 "missing",

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 536–540why, one step back
536 ]
537538539def test_hidden_option(runner):540 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 542–544why, one step back
542 def cli(nope):
543 click.echo(nope)544

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 548–558why, one step back
548
549550def test_hidden_command(runner):551 @click.group()552 def cli():553 pass554555 @cli.command(hidden=True)556 def nope():557 pass558

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 562–576why, one step back
562
563564def test_hidden_group(runner):565 @click.group()566 def cli():567 pass568569 @cli.group(hidden=True)570 def subgroup():571 pass572573 @subgroup.command()574 def nope():575 pass576

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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