Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

559 lines · 15.3 KiB · Python

Last changed by

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

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 #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 360why, one step back
360

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 364why, one step back
364

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 368why, one step back
368

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

lines 371–375why, one step back
371 assert (
372 "Invalid value for '--start_date':"373 " invalid datetime format: 2015-09."374 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"375 ) in result.output

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

line 376why, one step back
376

Merge branch '7.x'David Lordbefore adoption7239794

lines 377–380why, one step back
377 result = runner.invoke(cli, ["--help"])
378 assert (379 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output380 )

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

lines 381–384why, one step back
381
382383def test_datetime_option_custom(runner):384 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

line 388why, one step back
388

Merge branch '7.x'David Lordbefore adoption7239794

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

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

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

Merge branch '7.x'David Lordbefore adoption7239794

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

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

lines 392–393why, one step back
392
393

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 397–399why, one step back
397 def cli(x):
398 click.echo(x)399

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 403why, one step back
403

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 409why, one step back
409 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 410–411why, one step back
410
411 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 413–415why, one step back
413 def clamp(x):
414 click.echo(x)415

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 419why, one step back
419

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 423why, one step back
423

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 427–430why, one step back
427
428429def test_float_range_option(runner):430 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 432–434why, one step back
432 def cli(x):
433 click.echo(x)434

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 438why, one step back
438

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

line 444why, one step back
444 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 445–446why, one step back
445
446 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 448–450why, one step back
448 def clamp(x):
449 click.echo(x)450

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 454why, one step back
454

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

line 458why, one step back
458

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 462–465why, one step back
462
463464def test_required_option(runner):465 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 467–471why, one step back
467 def cli(foo):
468 click.echo(foo)469470 result = runner.invoke(cli, [])471 assert result.exit_code == 2

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 473–482why, one step back
473
474475def test_evaluation_order(runner):476 called = []477478 def memo(ctx, param, value):479 called.append(value)480 return value481482 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

lines 483–489why, one step back
483 @click.option("--missing", default="missing", is_eager=False, callback=memo)
484 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)485 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)486 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)487 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)488 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)489 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 490–492why, one step back
490 def cli(**x):
491 pass492

Merge branch '7.x'David Lordbefore adoption7239794

lines 493–505why, one step back
493 result = runner.invoke(
494 cli,495 [496 "--eager-flag2",497 "--eager-flag1",498 "--normal-flag2",499 "--eager-flag3",500 "--normal-flag3",501 "--normal-flag3",502 "--normal-flag1",503 "--normal-flag1",504 ],505 )

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 506–507why, one step back
506 assert not result.exception
507 assert called == [

Merge branch '7.x'David Lordbefore adoption7239794

lines 508–514why, one step back
508 "eager2",
509 "eager1",510 "eager3",511 "normal2",512 "normal3",513 "normal1",514 "missing",

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 515–519why, one step back
515 ]
516517518def test_hidden_option(runner):519 @click.command()

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 521–523why, one step back
521 def cli(nope):
522 click.echo(nope)523

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 527–537why, one step back
527
528529def test_hidden_command(runner):530 @click.group()531 def cli():532 pass533534 @cli.command(hidden=True)535 def nope():536 pass537

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

lines 541–555why, one step back
541
542543def test_hidden_group(runner):544 @click.group()545 def cli():546 pass547548 @cli.group(hidden=True)549 def subgroup():550 pass551552 @subgroup.command()553 def nope():554 pass555

Merge branch '7.x'David Lordbefore adoption7239794

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

Fix typo (synching -> syncing)mholtzscherbefore adoption55682f6

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

Merge branch '7.x'David Lordbefore adoption7239794

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