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 fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
lines 1–3why, one step back1# -*- coding: utf-8 -*-2import os3import uuidapply reorder-python-importsDavid Lordbefore adoption488739d
line 4why, one step back4Fix typo (#817)scottbeldenbefore adoption950463b
lines 5–11why, one step back5import click678def test_basic_functionality(runner):9 @click.command()10 def cli():11 """Hello World!"""apply blackDavid Lordbefore adoption93ba3ba
line 12why, one step back12 click.echo("I EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
line 13why, one step back13apply blackDavid Lordbefore adoption93ba3ba
line 14why, one step back14 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 15why, one step back15 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
lines 16–17why, one step back16 assert "Hello World!" in result.output17 assert "Show this message and exit." in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 18why, one step back18 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
line 19why, one step back19 assert "I EXECUTED" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 20–22why, one step back2021 result = runner.invoke(cli, [])22 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 23why, one step back23 assert "I EXECUTED" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 24–26why, one step back24 assert result.exit_code == 02526Merge pull request #1481 from pallets/command-reprDavid Lordbefore adoption0fc0a42
lines 27–39why, one step back27def test_repr():28 @click.command()29 def command():30 pass3132 @click.group()33 def group():34 pass3536 @group.command()37 def subcommand():38 pass39apply blackDavid Lordbefore adoption93ba3ba
lines 40–42why, one step back40 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 back4344Fix typo (#817)scottbeldenbefore adoption950463b
lines 45–49why, one step back45def test_return_values():46 @click.command()47 def cli():48 return 4249apply blackDavid Lordbefore adoption93ba3ba
line 50why, one step back50 with cli.make_context("foo", []) as ctx:Fix typo (#817)scottbeldenbefore adoption950463b
line 51why, one step back51 rv = cli.invoke(ctx)apply flake8David Lordbefore adoption5f75f9e
line 52why, one step back52 assert rv == 42Fix typo (#817)scottbeldenbefore adoption950463b
lines 53–58why, one step back535455def test_basic_group(runner):56 @click.group()57 def cli():58 """This is the root."""apply blackDavid Lordbefore adoption93ba3ba
line 59why, one step back59 click.echo("ROOT EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
lines 60–63why, one step back6061 @cli.command()62 def subcommand():63 """This is a subcommand."""apply blackDavid Lordbefore adoption93ba3ba
line 64why, one step back64 click.echo("SUBCOMMAND EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
line 65why, one step back65apply blackDavid Lordbefore adoption93ba3ba
line 66why, one step back66 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 67why, one step back67 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
lines 68–70why, one step back68 assert "COMMAND [ARGS]..." in result.output69 assert "This is the root" in result.output70 assert "This is a subcommand." in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 71why, one step back71 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
line 72why, one step back72 assert "ROOT EXECUTED" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 73why, one step back73apply blackDavid Lordbefore adoption93ba3ba
line 74why, one step back74 result = runner.invoke(cli, ["subcommand"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 75–76why, one step back75 assert not result.exception76 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
lines 77–78why, one step back77 assert "ROOT EXECUTED" in result.output78 assert "SUBCOMMAND EXECUTED" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 79–82why, one step back798081def test_basic_option(runner):82 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 83why, one step back83 @click.option("--foo", default="no value")Fix typo (#817)scottbeldenbefore adoption950463b
line 84why, one step back84 def cli(foo):apply blackDavid Lordbefore adoption93ba3ba
line 85why, one step back85 click.echo("FOO:[%s]" % foo)Fix typo (#817)scottbeldenbefore adoption950463b
lines 86–88why, one step back8687 result = runner.invoke(cli, [])88 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 89why, one step back89 assert "FOO:[no value]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 90why, one step back90apply blackDavid Lordbefore adoption93ba3ba
line 91why, one step back91 result = runner.invoke(cli, ["--foo=42"])Fix typo (#817)scottbeldenbefore adoption950463b
line 92why, one step back92 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 93why, one step back93 assert "FOO:[42]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 94why, one step back94apply blackDavid Lordbefore adoption93ba3ba
line 95why, one step back95 result = runner.invoke(cli, ["--foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 96why, one step back96 assert result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 97why, one step back97 assert "--foo option requires an argument" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 98why, one step back98apply blackDavid Lordbefore adoption93ba3ba
line 99why, one step back99 result = runner.invoke(cli, ["--foo="])Fix typo (#817)scottbeldenbefore adoption950463b
line 100why, one step back100 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 101why, one step back101 assert "FOO:[]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 102why, one step back102apply blackDavid Lordbefore adoption93ba3ba
line 103why, one step back103 result = runner.invoke(cli, [u"--foo=\N{SNOWMAN}"])Fix typo (#817)scottbeldenbefore adoption950463b
line 104why, one step back104 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 105why, one step back105 assert u"FOO:[\N{SNOWMAN}]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 106–109why, one step back106107108def test_int_option(runner):109 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 110why, one step back110 @click.option("--foo", default=42)Fix typo (#817)scottbeldenbefore adoption950463b
line 111why, one step back111 def cli(foo):apply blackDavid Lordbefore adoption93ba3ba
line 112why, one step back112 click.echo("FOO:[%s]" % (foo * 2))Fix typo (#817)scottbeldenbefore adoption950463b
lines 113–115why, one step back113114 result = runner.invoke(cli, [])115 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 116why, one step back116 assert "FOO:[84]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 117why, one step back117apply blackDavid Lordbefore adoption93ba3ba
line 118why, one step back118 result = runner.invoke(cli, ["--foo=23"])Fix typo (#817)scottbeldenbefore adoption950463b
line 119why, one step back119 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 120why, one step back120 assert "FOO:[46]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 121why, one step back121apply blackDavid Lordbefore adoption93ba3ba
line 122why, one step back122 result = runner.invoke(cli, ["--foo=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 123why, one step back123 assert result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 124why, one step back124 assert 'Invalid value for "--foo": bar is not a valid integer' in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 125–128why, one step back125126127def test_uuid_option(runner):128 @click.command()apply blackDavid Lordbefore adoption93ba3ba
lines 129–131why, one step back129 @click.option(130 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID131 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 132–133why, one step back132 def cli(u):133 assert type(u) is uuid.UUIDapply blackDavid Lordbefore adoption93ba3ba
line 134why, one step back134 click.echo("U:[%s]" % u)Fix typo (#817)scottbeldenbefore adoption950463b
lines 135–137why, one step back135136 result = runner.invoke(cli, [])137 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 138why, one step back138 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 139why, one step back139apply blackDavid Lordbefore adoption93ba3ba
line 140why, one step back140 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])Fix typo (#817)scottbeldenbefore adoption950463b
line 141why, one step back141 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 142why, one step back142 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 143why, one step back143apply blackDavid Lordbefore adoption93ba3ba
line 144why, one step back144 result = runner.invoke(cli, ["--u=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 145why, one step back145 assert result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 146why, one step back146 assert 'Invalid value for "--u": bar is not a valid UUID value' in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 147–150why, one step back147148149def test_float_option(runner):150 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 151why, one step back151 @click.option("--foo", default=42, type=click.FLOAT)Fix typo (#817)scottbeldenbefore adoption950463b
lines 152–153why, one step back152 def cli(foo):153 assert type(foo) is floatapply blackDavid Lordbefore adoption93ba3ba
line 154why, one step back154 click.echo("FOO:[%s]" % foo)Fix typo (#817)scottbeldenbefore adoption950463b
lines 155–157why, one step back155156 result = runner.invoke(cli, [])157 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 158why, one step back158 assert "FOO:[42.0]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 159why, one step back159apply blackDavid Lordbefore adoption93ba3ba
line 160why, one step back160 result = runner.invoke(cli, ["--foo=23.5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 161why, one step back161 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 162why, one step back162 assert "FOO:[23.5]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 163why, one step back163apply blackDavid Lordbefore adoption93ba3ba
line 164why, one step back164 result = runner.invoke(cli, ["--foo=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 165why, one step back165 assert result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 166why, one step back166 assert 'Invalid value for "--foo": bar is not a valid float' in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 167–170why, one step back167168169def test_boolean_option(runner):170 for default in True, False:apply blackDavid Lordbefore adoption93ba3ba
line 171why, one step back171Fix typo (#817)scottbeldenbefore adoption950463b
line 172why, one step back172 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 173why, one step back173 @click.option("--with-foo/--without-foo", default=default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 174–176why, one step back174 def cli(with_foo):175 click.echo(with_foo)176apply blackDavid Lordbefore adoption93ba3ba
line 177why, one step back177 result = runner.invoke(cli, ["--with-foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 178why, one step back178 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
lines 179–180why, one step back179 assert result.output == "True\n"180 result = runner.invoke(cli, ["--without-foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 181why, one step back181 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 182why, one step back182 assert result.output == "False\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 183–184why, one step back183 result = runner.invoke(cli, [])184 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 185why, one step back185 assert result.output == "%s\n" % defaultFix typo (#817)scottbeldenbefore adoption950463b
lines 186–187why, one step back186187 for default in True, False:apply blackDavid Lordbefore adoption93ba3ba
line 188why, one step back188Fix typo (#817)scottbeldenbefore adoption950463b
line 189why, one step back189 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 190why, one step back190 @click.option("--flag", is_flag=True, default=default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 191–193why, one step back191 def cli(flag):192 click.echo(flag)193apply blackDavid Lordbefore adoption93ba3ba
line 194why, one step back194 result = runner.invoke(cli, ["--flag"])Fix typo (#817)scottbeldenbefore adoption950463b
line 195why, one step back195 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 196why, one step back196 assert result.output == "%s\n" % (not default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 197–198why, one step back197 result = runner.invoke(cli, [])198 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 199why, one step back199 assert result.output == "%s\n" % (default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 200–201why, one step back200201Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 202–203why, one step back202def test_boolean_conversion(runner):203 for default in True, False:apply blackDavid Lordbefore adoption93ba3ba
line 204why, one step back204Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 205why, one step back205 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 206why, one step back206 @click.option("--flag", default=default, type=bool)Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 207–209why, one step back207 def cli(flag):208 click.echo(flag)209apply blackDavid Lordbefore adoption93ba3ba
lines 210–211why, one step back210 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 back212 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 213why, one step back213 assert result.output == "True\n"Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 214why, one step back214apply blackDavid Lordbefore adoption93ba3ba
lines 215–216why, one step back215 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 back217 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 218why, one step back218 assert result.output == "False\n"Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 219–221why, one step back219220 result = runner.invoke(cli, [])221 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 222why, one step back222 assert result.output == "%s\n" % defaultMerge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 223–224why, one step back223224Fix typo (#817)scottbeldenbefore adoption950463b
lines 225–226why, one step back225def test_file_option(runner):226 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 227why, one step back227 @click.option("--file", type=click.File("w"))Fix typo (#817)scottbeldenbefore adoption950463b
line 228why, one step back228 def input(file):apply blackDavid Lordbefore adoption93ba3ba
line 229why, one step back229 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 230–231why, one step back230231 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 232why, one step back232 @click.option("--file", type=click.File("r"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 233–236why, one step back233 def output(file):234 click.echo(file.read())235236 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
lines 237–238why, one step back237 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 back239240 assert not result_in.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 241why, one step back241 assert result_in.output == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 242why, one step back242 assert not result_out.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 243why, one step back243 assert result_out.output == "Hello World!\n\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 244–249why, one step back244245246def test_file_lazy_mode(runner):247 do_io = False248249 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 250why, one step back250 @click.option("--file", type=click.File("w"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 251–252why, one step back251 def input(file):252 if do_io:apply blackDavid Lordbefore adoption93ba3ba
line 253why, one step back253 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 254–255why, one step back254255 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 256why, one step back256 @click.option("--file", type=click.File("r"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 257–260why, one step back257 def output(file):258 pass259260 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
line 261why, one step back261 os.mkdir("example.txt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 262–263why, one step back262263 do_io = Trueapply blackDavid Lordbefore adoption93ba3ba
line 264why, one step back264 result_in = runner.invoke(input, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 265–267why, one step back265 assert result_in.exit_code == 1266267 do_io = Falseapply blackDavid Lordbefore adoption93ba3ba
line 268why, one step back268 result_in = runner.invoke(input, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 269–270why, one step back269 assert result_in.exit_code == 0270apply blackDavid Lordbefore adoption93ba3ba
line 271why, one step back271 result_out = runner.invoke(output, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 272–274why, one step back272 assert result_out.exception273274 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 275why, one step back275 @click.option("--file", type=click.File("w", lazy=False))Fix typo (#817)scottbeldenbefore adoption950463b
line 276why, one step back276 def input_non_lazy(file):apply blackDavid Lordbefore adoption93ba3ba
line 277why, one step back277 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 278–279why, one step back278279 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
lines 280–281why, one step back280 os.mkdir("example.txt")281 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
line 282why, one step back282 assert result_in.exit_code == 2apply blackDavid Lordbefore adoption93ba3ba
lines 283–284why, one step back283 assert (284 'Invalid value for "--file": Could not open file: example.txt'Fix typo (#817)scottbeldenbefore adoption950463b
line 285why, one step back285 in result_in.outputapply blackDavid Lordbefore adoption93ba3ba
line 286why, one step back286 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 287–290why, one step back287288289def test_path_option(runner):290 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 291why, one step back291 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Fix typo (#817)scottbeldenbefore adoption950463b
line 292why, one step back292 def write_to_dir(o):apply blackDavid Lordbefore adoption93ba3ba
lines 293–294why, one step back293 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 back295296 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
line 297why, one step back297 os.mkdir("test")Fix typo (#817)scottbeldenbefore adoption950463b
line 298why, one step back298apply blackDavid Lordbefore adoption93ba3ba
line 299why, one step back299 result = runner.invoke(write_to_dir, ["-O", "test"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 300–301why, one step back300 assert not result.exception301apply blackDavid Lordbefore adoption93ba3ba
lines 302–303why, one step back302 with open("test/foo.txt", "rb") as f:303 assert f.read() == b"meh\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 304why, one step back304apply blackDavid Lordbefore adoption93ba3ba
lines 305–307why, one step back305 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 back308 in result.outputapply blackDavid Lordbefore adoption93ba3ba
line 309why, one step back309 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 310–311why, one step back310311 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 312why, one step back312 @click.option("-f", type=click.Path(exists=True))Fix typo (#817)scottbeldenbefore adoption950463b
line 313why, one step back313 def showtype(f):apply blackDavid Lordbefore adoption93ba3ba
lines 314–315why, one step back314 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 back316317 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
lines 318–321why, one step back318 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 back322apply blackDavid Lordbefore adoption93ba3ba
lines 323–325why, one step back323 result = runner.invoke(showtype, ["-f", "."])324 assert "is_file=False" in result.output325 assert "is_dir=True" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 326–327why, one step back326327 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 328why, one step back328 @click.option("-f", type=click.Path())Fix typo (#817)scottbeldenbefore adoption950463b
line 329why, one step back329 def exists(f):apply blackDavid Lordbefore adoption93ba3ba
line 330why, one step back330 click.echo("exists=%s" % os.path.exists(f))Fix typo (#817)scottbeldenbefore adoption950463b
lines 331–332why, one step back331332 with runner.isolated_filesystem():apply blackDavid Lordbefore adoption93ba3ba
lines 333–334why, one step back333 result = runner.invoke(exists, ["-f", "xxx"])334 assert "exists=False" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 335why, one step back335apply blackDavid Lordbefore adoption93ba3ba
lines 336–337why, one step back336 result = runner.invoke(exists, ["-f", "."])337 assert "exists=True" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 338–341why, one step back338339340def test_choice_option(runner):341 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 342why, one step back342 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Fix typo (#817)scottbeldenbefore adoption950463b
lines 343–345why, one step back343 def cli(method):344 click.echo(method)345apply blackDavid Lordbefore adoption93ba3ba
line 346why, one step back346 result = runner.invoke(cli, ["--method=foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 347why, one step back347 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 348why, one step back348 assert result.output == "foo\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 349why, one step back349apply blackDavid Lordbefore adoption93ba3ba
line 350why, one step back350 result = runner.invoke(cli, ["--method=meh"])Fix typo (#817)scottbeldenbefore adoption950463b
line 351why, one step back351 assert result.exit_code == 2apply blackDavid Lordbefore adoption93ba3ba
lines 352–355why, one step back352 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 back356apply blackDavid Lordbefore adoption93ba3ba
lines 357–358why, one step back357 result = runner.invoke(cli, ["--help"])358 assert "--method [foo|bar|baz]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 359–360why, one step back359360Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 361–362why, one step back361def test_datetime_option_default(runner):362 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 363why, one step back363 @click.option("--start_date", type=click.DateTime())Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 364why, one step back364 def cli(start_date):apply blackDavid Lordbefore adoption93ba3ba
line 365why, one step back365 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 back366apply blackDavid Lordbefore adoption93ba3ba
line 367why, one step back367 result = runner.invoke(cli, ["--start_date=2015-09-29"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 368why, one step back368 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 369why, one step back369 assert result.output == "2015-09-29T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 370why, one step back370apply blackDavid Lordbefore adoption93ba3ba
line 371why, one step back371 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 back372 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 373why, one step back373 assert result.output == "2015-09-29T09:11:22\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 374why, one step back374apply blackDavid Lordbefore adoption93ba3ba
line 375why, one step back375 result = runner.invoke(cli, ["--start_date=2015-09"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 376why, one step back376 assert result.exit_code == 2apply blackDavid Lordbefore adoption93ba3ba
lines 377–381why, one step back377 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.outputMerge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 382why, one step back382apply blackDavid Lordbefore adoption93ba3ba
lines 383–386why, one step back383 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 back387388389def test_datetime_option_custom(runner):390 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 391why, one step back391 @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 back392 def cli(start_date):apply blackDavid Lordbefore adoption93ba3ba
line 393why, one step back393 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 back394apply blackDavid Lordbefore adoption93ba3ba
line 395why, one step back395 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 396why, one step back396 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 397why, one step back397 assert result.output == "2010-06-05T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 398–399why, one step back398399Fix typo (#817)scottbeldenbefore adoption950463b
lines 400–401why, one step back400def test_int_range_option(runner):401 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 402why, one step back402 @click.option("--x", type=click.IntRange(0, 5))Fix typo (#817)scottbeldenbefore adoption950463b
lines 403–405why, one step back403 def cli(x):404 click.echo(x)405apply blackDavid Lordbefore adoption93ba3ba
line 406why, one step back406 result = runner.invoke(cli, ["--x=5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 407why, one step back407 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 408why, one step back408 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 409why, one step back409apply blackDavid Lordbefore adoption93ba3ba
line 410why, one step back410 result = runner.invoke(cli, ["--x=6"])Fix typo (#817)scottbeldenbefore adoption950463b
line 411why, one step back411 assert result.exit_code == 2apply blackDavid Lordbefore adoption93ba3ba
lines 412–413why, one step back412 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 back414 in result.outputapply blackDavid Lordbefore adoption93ba3ba
line 415why, one step back415 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 416–417why, one step back416417 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 418why, one step back418 @click.option("--x", type=click.IntRange(0, 5, clamp=True))Fix typo (#817)scottbeldenbefore adoption950463b
lines 419–421why, one step back419 def clamp(x):420 click.echo(x)421apply blackDavid Lordbefore adoption93ba3ba
line 422why, one step back422 result = runner.invoke(clamp, ["--x=5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 423why, one step back423 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 424why, one step back424 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 425why, one step back425apply blackDavid Lordbefore adoption93ba3ba
line 426why, one step back426 result = runner.invoke(clamp, ["--x=6"])Fix typo (#817)scottbeldenbefore adoption950463b
line 427why, one step back427 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 428why, one step back428 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 429why, one step back429apply blackDavid Lordbefore adoption93ba3ba
line 430why, one step back430 result = runner.invoke(clamp, ["--x=-1"])Fix typo (#817)scottbeldenbefore adoption950463b
line 431why, one step back431 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 432why, one step back432 assert result.output == "0\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 433–436why, one step back433434435def test_float_range_option(runner):436 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 437why, one step back437 @click.option("--x", type=click.FloatRange(0, 5))Fix typo (#817)scottbeldenbefore adoption950463b
lines 438–440why, one step back438 def cli(x):439 click.echo(x)440apply blackDavid Lordbefore adoption93ba3ba
line 441why, one step back441 result = runner.invoke(cli, ["--x=5.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 442why, one step back442 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 443why, one step back443 assert result.output == "5.0\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 444why, one step back444apply blackDavid Lordbefore adoption93ba3ba
line 445why, one step back445 result = runner.invoke(cli, ["--x=6.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 446why, one step back446 assert result.exit_code == 2apply blackDavid Lordbefore adoption93ba3ba
lines 447–448why, one step back447 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 back449 in result.outputapply blackDavid Lordbefore adoption93ba3ba
line 450why, one step back450 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 451–452why, one step back451452 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 453why, one step back453 @click.option("--x", type=click.FloatRange(0, 5, clamp=True))Fix typo (#817)scottbeldenbefore adoption950463b
lines 454–456why, one step back454 def clamp(x):455 click.echo(x)456apply blackDavid Lordbefore adoption93ba3ba
line 457why, one step back457 result = runner.invoke(clamp, ["--x=5.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 458why, one step back458 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 459why, one step back459 assert result.output == "5.0\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 460why, one step back460apply blackDavid Lordbefore adoption93ba3ba
line 461why, one step back461 result = runner.invoke(clamp, ["--x=6.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 462why, one step back462 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 463why, one step back463 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 464why, one step back464apply blackDavid Lordbefore adoption93ba3ba
line 465why, one step back465 result = runner.invoke(clamp, ["--x=-1.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 466why, one step back466 assert not result.exceptionapply blackDavid Lordbefore adoption93ba3ba
line 467why, one step back467 assert result.output == "0\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 468–471why, one step back468469470def test_required_option(runner):471 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 472why, one step back472 @click.option("--foo", required=True)Fix typo (#817)scottbeldenbefore adoption950463b
lines 473–483why, one step back473 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 = []483Merge branch '6.x-maintenance'Armin Ronacherbefore adoption7404b06
line 484why, one step back484 def memo(ctx, param, value):Fix typo (#817)scottbeldenbefore adoption950463b
lines 485–488why, one step back485 called.append(value)486 return value487488 @click.command()apply blackDavid Lordbefore adoption93ba3ba
lines 489–495why, one step back489 @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 back496 def cli(**x):497 pass498apply blackDavid Lordbefore adoption93ba3ba
lines 499–511why, one step back499 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 back512 assert not result.exception513 assert called == [apply blackDavid Lordbefore adoption93ba3ba
lines 514–520why, one step back514 "eager2",515 "eager1",516 "eager3",517 "normal2",518 "normal3",519 "normal1",520 "missing",Fix typo (#817)scottbeldenbefore adoption950463b
lines 521–525why, one step back521 ]522523524def test_hidden_option(runner):525 @click.command()apply blackDavid Lordbefore adoption93ba3ba
line 526why, one step back526 @click.option("--nope", hidden=True)Fix typo (#817)scottbeldenbefore adoption950463b
lines 527–529why, one step back527 def cli(nope):528 click.echo(nope)529apply blackDavid Lordbefore adoption93ba3ba
line 530why, one step back530 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 531why, one step back531 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
line 532why, one step back532 assert "--nope" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 533–543why, one step back533534535def test_hidden_command(runner):536 @click.group()537 def cli():538 pass539540 @cli.command(hidden=True)541 def nope():542 pass543apply blackDavid Lordbefore adoption93ba3ba
line 544why, one step back544 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 545why, one step back545 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
line 546why, one step back546 assert "nope" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 547–561why, one step back547548549def 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 pass561apply blackDavid Lordbefore adoption93ba3ba
line 562why, one step back562 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 563why, one step back563 assert result.exit_code == 0apply blackDavid Lordbefore adoption93ba3ba
lines 564–565why, one step back564 assert "subgroup" not in result.output565 assert "nope" not in result.output