test_basic.py
This file
Path
tests/test_basic.py
534 lines · 14.6 KiB · Python
Last changed by
Merge pull request #1405 from energizah/commands-listDavid Lordbefore adoption7147f41
History of this fileTake it
The walk stopped after 200 commits: lines older than 9db53b9 point at it.
Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 1–2why, one step back1import os2import uuidMerge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455
line 3why, one step back3from itertools import chainMerge branch '7.x'David Lordbefore adoption7239794
line 4why, one step back4Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455
lines 5–6why, one step back5import pytest6Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 7–13why, one step back7import click8910def test_basic_functionality(runner):11 @click.command()12 def cli():13 """Hello World!"""Merge branch '7.x'David Lordbefore adoption7239794
line 14why, one step back14 click.echo("I EXECUTED")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 15why, one step back15Merge branch '7.x'David Lordbefore adoption7239794
line 16why, one step back16 result = runner.invoke(cli, ["--help"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 17why, one step back17 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 18–19why, one step back18 assert "Hello World!" in result.output19 assert "Show this message and exit." in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 20why, one step back20 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 21why, one step back21 assert "I EXECUTED" not in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 22–24why, one step back2223 result = runner.invoke(cli, [])24 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 25why, one step back25 assert "I EXECUTED" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 26–28why, one step back26 assert result.exit_code == 02728Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a
lines 29–41why, one step back29def test_repr():30 @click.command()31 def command():32 pass3334 @click.group()35 def group():36 pass3738 @group.command()39 def subcommand():40 pass41Merge branch '7.x'David Lordbefore adoption7239794
lines 42–44why, one step back42 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 back4546Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 47–51why, one step back47def test_return_values():48 @click.command()49 def cli():50 return 4251Merge branch '7.x'David Lordbefore adoption7239794
line 52why, one step back52 with cli.make_context("foo", []) as ctx:Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 53why, one step back53 rv = cli.invoke(ctx)Merge pull request #1445 from tirkarthi/fix-syntax-warningJoshua Bronsonbefore adoption6c454c8
line 54why, one step back54 assert rv == 42Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 55–60why, one step back555657def 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 back61 click.echo("ROOT EXECUTED")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 62–65why, one step back6263 @cli.command()64 def subcommand():65 """This is a subcommand."""Merge branch '7.x'David Lordbefore adoption7239794
line 66why, one step back66 click.echo("SUBCOMMAND EXECUTED")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 67why, one step back67Merge branch '7.x'David Lordbefore adoption7239794
line 68why, one step back68 result = runner.invoke(cli, ["--help"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 69why, one step back69 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 70–72why, one step back70 assert "COMMAND [ARGS]..." in result.output71 assert "This is the root" in result.output72 assert "This is a subcommand." in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 73why, one step back73 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 74why, one step back74 assert "ROOT EXECUTED" not in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 75why, one step back75Merge branch '7.x'David Lordbefore adoption7239794
line 76why, one step back76 result = runner.invoke(cli, ["subcommand"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 77–78why, one step back77 assert not result.exception78 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 79–80why, one step back79 assert "ROOT EXECUTED" in result.output80 assert "SUBCOMMAND EXECUTED" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 81–82why, one step back8182Merge pull request #1405 from energizah/commands-listDavid Lordbefore adoption7147f41
lines 83–106why, one step back83def test_group_commands_dict(runner):84 """A Group can be built with a dict of commands."""8586 @click.command()87 def sub():88 click.echo("sub", nl=False)8990 cli = click.Group(commands={"other": sub})91 result = runner.invoke(cli, ["other"])92 assert result.output == "sub"939495def test_group_from_list(runner):96 """A Group can be built with a list of commands."""9798 @click.command()99 def sub():100 click.echo("sub", nl=False)101102 cli = click.Group(commands=[sub])103 result = runner.invoke(cli, ["sub"])104 assert result.output == "sub"105106Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 107–108why, one step back107def test_basic_option(runner):108 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 109why, one step back109 @click.option("--foo", default="no value")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 110why, one step back110 def cli(foo):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 111why, one step back111 click.echo(f"FOO:[{foo}]")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 112–114why, one step back112113 result = runner.invoke(cli, [])114 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 115why, one step back115 assert "FOO:[no value]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 116why, one step back116Merge branch '7.x'David Lordbefore adoption7239794
line 117why, one step back117 result = runner.invoke(cli, ["--foo=42"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 118why, one step back118 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 119why, one step back119 assert "FOO:[42]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 120why, one step back120Merge branch '7.x'David Lordbefore adoption7239794
line 121why, one step back121 result = runner.invoke(cli, ["--foo"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 122why, one step back122 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 123why, one step back123 assert "--foo option requires an argument" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 124why, one step back124Merge branch '7.x'David Lordbefore adoption7239794
line 125why, one step back125 result = runner.invoke(cli, ["--foo="])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 126why, one step back126 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 127why, one step back127 assert "FOO:[]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 128why, one step back128Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 129why, one step back129 result = runner.invoke(cli, ["--foo=\N{SNOWMAN}"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 130why, one step back130 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 131why, one step back131 assert "FOO:[\N{SNOWMAN}]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 132–135why, one step back132133134def test_int_option(runner):135 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 136why, one step back136 @click.option("--foo", default=42)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 137why, one step back137 def cli(foo):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 138why, one step back138 click.echo(f"FOO:[{foo * 2}]")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 139–141why, one step back139140 result = runner.invoke(cli, [])141 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 142why, one step back142 assert "FOO:[84]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 143why, one step back143Merge branch '7.x'David Lordbefore adoption7239794
line 144why, one step back144 result = runner.invoke(cli, ["--foo=23"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 145why, one step back145 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 146why, one step back146 assert "FOO:[46]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 147why, one step back147Merge branch '7.x'David Lordbefore adoption7239794
line 148why, one step back148 result = runner.invoke(cli, ["--foo=bar"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 149why, one step back149 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 150why, one step back150 assert "Invalid value for '--foo': bar is not a valid integer" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 151–154why, one step back151152153def test_uuid_option(runner):154 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 155–157why, one step back155 @click.option(156 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID157 )Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 158–159why, one step back158 def cli(u):159 assert type(u) is uuid.UUIDMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 160why, one step back160 click.echo(f"U:[{u}]")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 161–163why, one step back161162 result = runner.invoke(cli, [])163 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 164why, one step back164 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 165why, one step back165Merge branch '7.x'David Lordbefore adoption7239794
line 166why, one step back166 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 167why, one step back167 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 168why, one step back168 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 169why, one step back169Merge branch '7.x'David Lordbefore adoption7239794
line 170why, one step back170 result = runner.invoke(cli, ["--u=bar"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 171why, one step back171 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 172why, one step back172 assert "Invalid value for '--u': bar is not a valid UUID value" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 173–176why, one step back173174175def test_float_option(runner):176 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 177why, one step back177 @click.option("--foo", default=42, type=click.FLOAT)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 178–179why, one step back178 def cli(foo):179 assert type(foo) is floatMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 180why, one step back180 click.echo(f"FOO:[{foo}]")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 181–183why, one step back181182 result = runner.invoke(cli, [])183 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 184why, one step back184 assert "FOO:[42.0]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 185why, one step back185Merge branch '7.x'David Lordbefore adoption7239794
line 186why, one step back186 result = runner.invoke(cli, ["--foo=23.5"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 187why, one step back187 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 188why, one step back188 assert "FOO:[23.5]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 189why, one step back189Merge branch '7.x'David Lordbefore adoption7239794
line 190why, one step back190 result = runner.invoke(cli, ["--foo=bar"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 191why, one step back191 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 192why, one step back192 assert "Invalid value for '--foo': bar is not a valid float" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 193–196why, one step back193194195def test_boolean_option(runner):196 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 197why, one step back197Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 198why, one step back198 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 199why, one step back199 @click.option("--with-foo/--without-foo", default=default)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 200–202why, one step back200 def cli(with_foo):201 click.echo(with_foo)202Merge branch '7.x'David Lordbefore adoption7239794
line 203why, one step back203 result = runner.invoke(cli, ["--with-foo"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 204why, one step back204 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 205–206why, one step back205 assert result.output == "True\n"206 result = runner.invoke(cli, ["--without-foo"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 207why, one step back207 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 208why, one step back208 assert result.output == "False\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 209–210why, one step back209 result = runner.invoke(cli, [])210 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 211why, one step back211 assert result.output == f"{default}\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 212–213why, one step back212213 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 214why, one step back214Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 215why, one step back215 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 216why, one step back216 @click.option("--flag", is_flag=True, default=default)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 217–219why, one step back217 def cli(flag):218 click.echo(flag)219Merge branch '7.x'David Lordbefore adoption7239794
line 220why, one step back220 result = runner.invoke(cli, ["--flag"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 221why, one step back221 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 222why, one step back222 assert result.output == f"{not default}\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 223–224why, one step back223 result = runner.invoke(cli, [])224 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 225why, one step back225 assert result.output == f"{default}\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 226–227why, one step back226227Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455
lines 228–239why, one step back228@pytest.mark.parametrize(229 ("value", "expect"),230 chain(231 ((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),232 ((x, "False") for x in ("0", "false", "f", "no", "n", "off")),233 ),234)235def test_boolean_conversion(runner, value, expect):236 @click.command()237 @click.option("--flag", type=bool)238 def cli(flag):239 click.echo(flag, nl=False)Merge branch '7.x'David Lordbefore adoption7239794
line 240why, one step back240Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455
lines 241–242why, one step back241 result = runner.invoke(cli, ["--flag", value])242 assert result.output == expectMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 243why, one step back243Merge pull request #1630 from jwodder/more-boolsDavid Lordbefore adoption2815455
lines 244–245why, one step back244 result = runner.invoke(cli, ["--flag", value.title()])245 assert result.output == expectMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 246–249why, one step back246247248def test_file_option(runner):249 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 250why, one step back250 @click.option("--file", type=click.File("w"))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 251why, one step back251 def input(file):Merge branch '7.x'David Lordbefore adoption7239794
line 252why, one step back252 file.write("Hello World!\n")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 253–254why, one step back253254 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 255why, one step back255 @click.option("--file", type=click.File("r"))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 256–259why, one step back256 def output(file):257 click.echo(file.read())258259 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 260–261why, one step back260 result_in = runner.invoke(input, ["--file=example.txt"])261 result_out = runner.invoke(output, ["--file=example.txt"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 262–263why, one step back262263 assert not result_in.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 264why, one step back264 assert result_in.output == ""Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 265why, one step back265 assert not result_out.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 266why, one step back266 assert result_out.output == "Hello World!\n\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 267–272why, one step back267268269def test_file_lazy_mode(runner):270 do_io = False271272 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 273why, one step back273 @click.option("--file", type=click.File("w"))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 274–275why, one step back274 def input(file):275 if do_io:Merge branch '7.x'David Lordbefore adoption7239794
line 276why, one step back276 file.write("Hello World!\n")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 277–278why, one step back277278 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 279why, one step back279 @click.option("--file", type=click.File("r"))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 280–283why, one step back280 def output(file):281 pass282283 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 284why, one step back284 os.mkdir("example.txt")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 285–286why, one step back285286 do_io = TrueMerge branch '7.x'David Lordbefore adoption7239794
line 287why, one step back287 result_in = runner.invoke(input, ["--file=example.txt"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 288–290why, one step back288 assert result_in.exit_code == 1289290 do_io = FalseMerge branch '7.x'David Lordbefore adoption7239794
line 291why, one step back291 result_in = runner.invoke(input, ["--file=example.txt"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 292–293why, one step back292 assert result_in.exit_code == 0293Merge branch '7.x'David Lordbefore adoption7239794
line 294why, one step back294 result_out = runner.invoke(output, ["--file=example.txt"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 295–297why, one step back295 assert result_out.exception296297 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 298why, one step back298 @click.option("--file", type=click.File("w", lazy=False))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 299why, one step back299 def input_non_lazy(file):Merge branch '7.x'David Lordbefore adoption7239794
line 300why, one step back300 file.write("Hello World!\n")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 301–302why, one step back301302 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 303–304why, one step back303 os.mkdir("example.txt")304 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 305why, one step back305 assert result_in.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 306–307why, one step back306 assert (307 "Invalid value for '--file': Could not open file: example.txt"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 308why, one step back308 in result_in.outputMerge branch '7.x'David Lordbefore adoption7239794
line 309why, one step back309 )Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 310–313why, one step back310311312def test_path_option(runner):313 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 314why, one step back314 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 315why, one step back315 def write_to_dir(o):Merge branch '7.x'David Lordbefore adoption7239794
lines 316–317why, one step back316 with open(os.path.join(o, "foo.txt"), "wb") as f:317 f.write(b"meh\n")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 318–319why, one step back318319 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 320why, one step back320 os.mkdir("test")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 321why, one step back321Merge branch '7.x'David Lordbefore adoption7239794
line 322why, one step back322 result = runner.invoke(write_to_dir, ["-O", "test"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 323–324why, one step back323 assert not result.exception324Merge branch '7.x'David Lordbefore adoption7239794
lines 325–326why, one step back325 with open("test/foo.txt", "rb") as f:326 assert f.read() == b"meh\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 327why, one step back327Merge branch '7.x'David Lordbefore adoption7239794
lines 328–329why, one step back328 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])329 assert "is a file" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 330–331why, one step back330331 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 332why, one step back332 @click.option("-f", type=click.Path(exists=True))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 333why, one step back333 def showtype(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 334–335why, one step back334 click.echo(f"is_file={os.path.isfile(f)}")335 click.echo(f"is_dir={os.path.isdir(f)}")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 336–337why, one step back336337 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 338–339why, one step back338 result = runner.invoke(showtype, ["-f", "xxx"])339 assert "does not exist" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 340why, one step back340Merge branch '7.x'David Lordbefore adoption7239794
lines 341–343why, one step back341 result = runner.invoke(showtype, ["-f", "."])342 assert "is_file=False" in result.output343 assert "is_dir=True" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 344–345why, one step back344345 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 346why, one step back346 @click.option("-f", type=click.Path())Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 347why, one step back347 def exists(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 348why, one step back348 click.echo(f"exists={os.path.exists(f)}")Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 349–350why, one step back349350 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 351–352why, one step back351 result = runner.invoke(exists, ["-f", "xxx"])352 assert "exists=False" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 353why, one step back353Merge branch '7.x'David Lordbefore adoption7239794
lines 354–355why, one step back354 result = runner.invoke(exists, ["-f", "."])355 assert "exists=True" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 356–359why, one step back356357358def test_choice_option(runner):359 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 360why, one step back360 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 361–363why, one step back361 def cli(method):362 click.echo(method)363Merge branch '7.x'David Lordbefore adoption7239794
line 364why, one step back364 result = runner.invoke(cli, ["--method=foo"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 365why, one step back365 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 366why, one step back366 assert result.output == "foo\n"Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 367why, one step back367Merge branch '7.x'David Lordbefore adoption7239794
line 368why, one step back368 result = runner.invoke(cli, ["--method=meh"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 369why, one step back369 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 370–373why, one step back370 assert (371 "Invalid value for '--method': invalid choice: meh."372 " (choose from foo, bar, baz)" in result.output373 )Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 374why, one step back374Merge branch '7.x'David Lordbefore adoption7239794
lines 375–376why, one step back375 result = runner.invoke(cli, ["--help"])376 assert "--method [foo|bar|baz]" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 377–378why, one step back377378Merge pull request #1273 from 0xDEC0DE/issue/1272David Lordbefore adoptiond15f740
lines 379–399why, one step back379def test_choice_argument(runner):380 @click.command()381 @click.argument("method", type=click.Choice(["foo", "bar", "baz"]))382 def cli(method):383 click.echo(method)384385 result = runner.invoke(cli, ["foo"])386 assert not result.exception387 assert result.output == "foo\n"388389 result = runner.invoke(cli, ["meh"])390 assert result.exit_code == 2391 assert (392 "Invalid value for '{foo|bar|baz}': invalid choice: meh. "393 "(choose from foo, bar, baz)" in result.output394 )395396 result = runner.invoke(cli, ["--help"])397 assert "{foo|bar|baz}" in result.output398399Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 400–401why, one step back400def test_datetime_option_default(runner):401 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 402why, one step back402 @click.option("--start_date", type=click.DateTime())Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 403why, one step back403 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 404why, one step back404 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 405why, one step back405Merge branch '7.x'David Lordbefore adoption7239794
line 406why, one step back406 result = runner.invoke(cli, ["--start_date=2015-09-29"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 407why, one step back407 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 408why, one step back408 assert result.output == "2015-09-29T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 409why, one step back409Merge branch '7.x'David Lordbefore adoption7239794
line 410why, one step back410 result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 411why, one step back411 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 412why, one step back412 assert result.output == "2015-09-29T09:11:22\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 413why, one step back413Merge branch '7.x'David Lordbefore adoption7239794
line 414why, one step back414 result = runner.invoke(cli, ["--start_date=2015-09"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 415why, one step back415 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 416–420why, one step back416 assert (417 "Invalid value for '--start_date':"418 " invalid datetime format: 2015-09."419 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"420 ) in result.outputMerge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 421why, one step back421Merge branch '7.x'David Lordbefore adoption7239794
lines 422–425why, one step back422 result = runner.invoke(cli, ["--help"])423 assert (424 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output425 )Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 426–429why, one step back426427428def test_datetime_option_custom(runner):429 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 430why, one step back430 @click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 431why, one step back431 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 432why, one step back432 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 433why, one step back433Merge branch '7.x'David Lordbefore adoption7239794
line 434why, one step back434 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 435why, one step back435 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 436why, one step back436 assert result.output == "2010-06-05T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 437–438why, one step back437438Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 439–440why, one step back439def test_required_option(runner):440 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 441why, one step back441 @click.option("--foo", required=True)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 442–446why, one step back442 def cli(foo):443 click.echo(foo)444445 result = runner.invoke(cli, [])446 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 447why, one step back447 assert "Missing option '--foo'" in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 448–457why, one step back448449450def test_evaluation_order(runner):451 called = []452453 def memo(ctx, param, value):454 called.append(value)455 return value456457 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 458–464why, one step back458 @click.option("--missing", default="missing", is_eager=False, callback=memo)459 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)460 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)461 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)462 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)463 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)464 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 465–467why, one step back465 def cli(**x):466 pass467Merge branch '7.x'David Lordbefore adoption7239794
lines 468–480why, one step back468 result = runner.invoke(469 cli,470 [471 "--eager-flag2",472 "--eager-flag1",473 "--normal-flag2",474 "--eager-flag3",475 "--normal-flag3",476 "--normal-flag3",477 "--normal-flag1",478 "--normal-flag1",479 ],480 )Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 481–482why, one step back481 assert not result.exception482 assert called == [Merge branch '7.x'David Lordbefore adoption7239794
lines 483–489why, one step back483 "eager2",484 "eager1",485 "eager3",486 "normal2",487 "normal3",488 "normal1",489 "missing",Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 490–494why, one step back490 ]491492493def test_hidden_option(runner):494 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 495why, one step back495 @click.option("--nope", hidden=True)Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 496–498why, one step back496 def cli(nope):497 click.echo(nope)498Merge branch '7.x'David Lordbefore adoption7239794
line 499why, one step back499 result = runner.invoke(cli, ["--help"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 500why, one step back500 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 501why, one step back501 assert "--nope" not in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 502–512why, one step back502503504def test_hidden_command(runner):505 @click.group()506 def cli():507 pass508509 @cli.command(hidden=True)510 def nope():511 pass512Merge branch '7.x'David Lordbefore adoption7239794
line 513why, one step back513 result = runner.invoke(cli, ["--help"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 514why, one step back514 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 515why, one step back515 assert "nope" not in result.outputMerge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
lines 516–530why, one step back516517518def test_hidden_group(runner):519 @click.group()520 def cli():521 pass522523 @cli.group(hidden=True)524 def subgroup():525 pass526527 @subgroup.command()528 def nope():529 pass530Merge branch '7.x'David Lordbefore adoption7239794
line 531why, one step back531 result = runner.invoke(cli, ["--help"])Merge pull request #835 from vivekanand1101/patch-1David Lordbefore adoption9db53b9
line 532why, one step back532 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 533–534why, one step back533 assert "subgroup" not in result.output534 assert "nope" not in result.output