Skip to content
Myr

test_basic.py

This file

Path

tests/test_basic.py

565 lines · 15.6 KiB · Python

Last changed by

apply flake8David Lordbefore adoption5f75f9e

History of this file

Take it

The walk stopped after 200 commits: lines older than 950463b point at it.

Fix typo (#817)scottbeldenbefore adoption950463b

lines 1–3why, one step back
1# -*- coding: utf-8 -*-
2import os3import uuid

apply reorder-python-importsDavid Lordbefore adoption488739d

line 4why, one step back
4

Fix typo (#817)scottbeldenbefore adoption950463b

lines 5–11why, one step back
5import click
678def test_basic_functionality(runner):9 @click.command()10 def cli():11 """Hello World!"""

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 13why, one step back
13

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 24–26why, one step back
24 assert result.exit_code == 0
2526

Merge pull request #1481 from pallets/command-reprDavid Lordbefore adoption0fc0a42

lines 27–39why, one step back
27def test_repr():
28 @click.command()29 def command():30 pass3132 @click.group()33 def group():34 pass3536 @group.command()37 def subcommand():38 pass39

apply blackDavid Lordbefore adoption93ba3ba

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

Merge pull request #1481 from pallets/command-reprDavid Lordbefore adoption0fc0a42

lines 43–44why, one step back
43
44

Fix typo (#817)scottbeldenbefore adoption950463b

lines 45–49why, one step back
45def test_return_values():
46 @click.command()47 def cli():48 return 4249

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply flake8David Lordbefore adoption5f75f9e

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 53–58why, one step back
53
5455def test_basic_group(runner):56 @click.group()57 def cli():58 """This is the root."""

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 65why, one step back
65

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 73why, one step back
73

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 75–76why, one step back
75 assert not result.exception
76 assert result.exit_code == 0

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 79–82why, one step back
79
8081def test_basic_option(runner):82 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 85why, one step back
85 click.echo("FOO:[%s]" % foo)

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 90why, one step back
90

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 94why, one step back
94

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 98why, one step back
98

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 102why, one step back
102

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 106–109why, one step back
106
107108def test_int_option(runner):109 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 112why, one step back
112 click.echo("FOO:[%s]" % (foo * 2))

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 117why, one step back
117

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 121why, one step back
121

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 125–128why, one step back
125
126127def test_uuid_option(runner):128 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 134why, one step back
134 click.echo("U:[%s]" % u)

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 139why, one step back
139

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 143why, one step back
143

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 147–150why, one step back
147
148149def test_float_option(runner):150 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 154why, one step back
154 click.echo("FOO:[%s]" % foo)

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 159why, one step back
159

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 163why, one step back
163

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 167–170why, one step back
167
168169def test_boolean_option(runner):170 for default in True, False:

apply blackDavid Lordbefore adoption93ba3ba

line 171why, one step back
171

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 185why, one step back
185 assert result.output == "%s\n" % default

Fix typo (#817)scottbeldenbefore adoption950463b

lines 186–187why, one step back
186
187 for default in True, False:

apply blackDavid Lordbefore adoption93ba3ba

line 188why, one step back
188

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 196why, one step back
196 assert result.output == "%s\n" % (not default)

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 199why, one step back
199 assert result.output == "%s\n" % (default)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 200–201why, one step back
200
201

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

lines 202–203why, one step back
202def test_boolean_conversion(runner):
203 for default in True, False:

apply blackDavid Lordbefore adoption93ba3ba

line 204why, one step back
204

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

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

apply blackDavid Lordbefore adoption93ba3ba

line 206why, one step back
206 @click.option("--flag", default=default, type=bool)

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

lines 207–209why, one step back
207 def cli(flag):
208 click.echo(flag)209

apply blackDavid Lordbefore adoption93ba3ba

lines 210–211why, one step back
210 for value in "true", "t", "1", "yes", "y":
211 result = runner.invoke(cli, ["--flag", value])

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

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

apply blackDavid Lordbefore adoption93ba3ba

line 213why, one step back
213 assert result.output == "True\n"

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

line 214why, one step back
214

apply blackDavid Lordbefore adoption93ba3ba

lines 215–216why, one step back
215 for value in "false", "f", "0", "no", "n":
216 result = runner.invoke(cli, ["--flag", value])

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

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

apply blackDavid Lordbefore adoption93ba3ba

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

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

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

apply blackDavid Lordbefore adoption93ba3ba

line 222why, one step back
222 assert result.output == "%s\n" % default

Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79

lines 223–224why, one step back
223
224

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 233–236why, one step back
233 def output(file):
234 click.echo(file.read())235236 with runner.isolated_filesystem():

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 244–249why, one step back
244
245246def test_file_lazy_mode(runner):247 do_io = False248249 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 257–260why, one step back
257 def output(file):
258 pass259260 with runner.isolated_filesystem():

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 265–267why, one step back
265 assert result_in.exit_code == 1
266267 do_io = False

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 272–274why, one step back
272 assert result_out.exception
273274 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 286why, one step back
286 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 287–290why, one step back
287
288289def test_path_option(runner):290 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 298why, one step back
298

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 304why, one step back
304

apply blackDavid Lordbefore adoption93ba3ba

lines 305–307why, one step back
305 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])
306 assert (307 'Invalid value for "-O": Directory "test/foo.txt" is a file.'

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 309why, one step back
309 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 310–311why, one step back
310
311 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

lines 314–315why, one step back
314 click.echo("is_file=%s" % os.path.isfile(f))
315 click.echo("is_dir=%s" % os.path.isdir(f))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 316–317why, one step back
316
317 with runner.isolated_filesystem():

apply blackDavid Lordbefore adoption93ba3ba

lines 318–321why, one step back
318 result = runner.invoke(showtype, ["-f", "xxx"])
319 assert (320 'Error: Invalid value for "-f": Path "xxx" does not exist' in result.output321 )

Fix typo (#817)scottbeldenbefore adoption950463b

line 322why, one step back
322

apply blackDavid Lordbefore adoption93ba3ba

lines 323–325why, one step back
323 result = runner.invoke(showtype, ["-f", "."])
324 assert "is_file=False" in result.output325 assert "is_dir=True" in result.output

Fix typo (#817)scottbeldenbefore adoption950463b

lines 326–327why, one step back
326
327 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 330why, one step back
330 click.echo("exists=%s" % os.path.exists(f))

Fix typo (#817)scottbeldenbefore adoption950463b

lines 331–332why, one step back
331
332 with runner.isolated_filesystem():

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 335why, one step back
335

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 338–341why, one step back
338
339340def test_choice_option(runner):341 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 343–345why, one step back
343 def cli(method):
344 click.echo(method)345

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 349why, one step back
349

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

lines 352–355why, one step back
352 assert (
353 'Invalid value for "--method": invalid choice: meh. '354 "(choose from foo, bar, baz)" in result.output355 )

Fix typo (#817)scottbeldenbefore adoption950463b

line 356why, one step back
356

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 359–360why, one step back
359
360

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

line 366why, one step back
366

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

line 370why, one step back
370

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

line 374why, one step back
374

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

lines 377–381why, one step back
377 assert (
378 'Invalid value for "--start_date": '379 "invalid datetime format: 2015-09. "380 "(choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"381 ) in result.output

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

line 382why, one step back
382

apply blackDavid Lordbefore adoption93ba3ba

lines 383–386why, one step back
383 result = runner.invoke(cli, ["--help"])
384 assert (385 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output386 )

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

lines 387–390why, one step back
387
388389def test_datetime_option_custom(runner):390 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

line 394why, one step back
394

apply blackDavid Lordbefore adoption93ba3ba

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

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

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

apply blackDavid Lordbefore adoption93ba3ba

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

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

lines 398–399why, one step back
398
399

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 403–405why, one step back
403 def cli(x):
404 click.echo(x)405

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 409why, one step back
409

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 415why, one step back
415 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 416–417why, one step back
416
417 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 425why, one step back
425

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 429why, one step back
429

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 433–436why, one step back
433
434435def test_float_range_option(runner):436 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 438–440why, one step back
438 def cli(x):
439 click.echo(x)440

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 444why, one step back
444

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

line 450why, one step back
450 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 451–452why, one step back
451
452 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 460why, one step back
460

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

line 464why, one step back
464

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 468–471why, one step back
468
469470def test_required_option(runner):471 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 473–483why, one step back
473 def cli(foo):
474 click.echo(foo)475476 result = runner.invoke(cli, [])477 assert result.exit_code == 2478 assert 'Missing option "--foo"' in result.output479480481def test_evaluation_order(runner):482 called = []483

Merge branch '6.x-maintenance'Armin Ronacherbefore adoption7404b06

line 484why, one step back
484 def memo(ctx, param, value):

Fix typo (#817)scottbeldenbefore adoption950463b

lines 485–488why, one step back
485 called.append(value)
486 return value487488 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

lines 489–495why, one step back
489 @click.option("--missing", default="missing", is_eager=False, callback=memo)
490 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)491 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)492 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)493 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)494 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)495 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)

Fix typo (#817)scottbeldenbefore adoption950463b

lines 496–498why, one step back
496 def cli(**x):
497 pass498

apply blackDavid Lordbefore adoption93ba3ba

lines 499–511why, one step back
499 result = runner.invoke(
500 cli,501 [502 "--eager-flag2",503 "--eager-flag1",504 "--normal-flag2",505 "--eager-flag3",506 "--normal-flag3",507 "--normal-flag3",508 "--normal-flag1",509 "--normal-flag1",510 ],511 )

Fix typo (#817)scottbeldenbefore adoption950463b

lines 512–513why, one step back
512 assert not result.exception
513 assert called == [

apply blackDavid Lordbefore adoption93ba3ba

lines 514–520why, one step back
514 "eager2",
515 "eager1",516 "eager3",517 "normal2",518 "normal3",519 "normal1",520 "missing",

Fix typo (#817)scottbeldenbefore adoption950463b

lines 521–525why, one step back
521 ]
522523524def test_hidden_option(runner):525 @click.command()

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 527–529why, one step back
527 def cli(nope):
528 click.echo(nope)529

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 533–543why, one step back
533
534535def test_hidden_command(runner):536 @click.group()537 def cli():538 pass539540 @cli.command(hidden=True)541 def nope():542 pass543

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

lines 547–561why, one step back
547
548549def test_hidden_group(runner):550 @click.group()551 def cli():552 pass553554 @cli.group(hidden=True)555 def subgroup():556 pass557558 @subgroup.command()559 def nope():560 pass561

apply blackDavid Lordbefore adoption93ba3ba

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

Fix typo (#817)scottbeldenbefore adoption950463b

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

apply blackDavid Lordbefore adoption93ba3ba

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