test_basic.py
This file
Path
tests/test_basic.py
549 lines · 14.9 KiB · Python
Last changed by
Merge pull request #1695 from srafi1/help-summaryAmy Leibefore adoptiona4763ef
History of this fileTake it
The walk stopped after 200 commits: lines older than bc53a96 point at it.
Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 15why, one step back15Merge branch '7.x'David Lordbefore adoption7239794
line 16why, one step back16 result = runner.invoke(cli, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 67why, one step back67Merge branch '7.x'David Lordbefore adoption7239794
line 68why, one step back68 result = runner.invoke(cli, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 75why, one step back75Merge branch '7.x'David Lordbefore adoption7239794
line 76why, one step back76 result = runner.invoke(cli, ["subcommand"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 120why, one step back120Merge branch '7.x'David Lordbefore adoption7239794
line 121why, one step back121 result = runner.invoke(cli, ["--foo"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 124why, one step back124Merge branch '7.x'David Lordbefore adoption7239794
line 125why, one step back125 result = runner.invoke(cli, ["--foo="])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 149why, one step back149 assert result.exceptionMerge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 150why, one step back150 assert "Invalid value for '--foo': 'bar' is not a valid integer." in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 171why, one step back171 assert result.exceptionMerge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 172why, one step back172 assert "Invalid value for '--u': 'bar' is not a valid UUID." in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 191why, one step back191 assert result.exceptionMerge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 192why, one step back192 assert "Invalid value for '--foo': 'bar' is not a valid float." in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
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 #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 305why, one step back305 assert result_in.exit_code == 2Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
line 306why, one step back306 assert "Invalid value for '--file': 'example.txt'" in result_in.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 307–310why, one step back307308309def test_path_option(runner):310 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 311why, one step back311 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 312why, one step back312 def write_to_dir(o):Merge branch '7.x'David Lordbefore adoption7239794
lines 313–314why, one step back313 with open(os.path.join(o, "foo.txt"), "wb") as f:314 f.write(b"meh\n")Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 315–316why, one step back315316 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 317why, one step back317 os.mkdir("test")Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 318why, one step back318Merge branch '7.x'David Lordbefore adoption7239794
line 319why, one step back319 result = runner.invoke(write_to_dir, ["-O", "test"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 320–321why, one step back320 assert not result.exception321Merge branch '7.x'David Lordbefore adoption7239794
lines 322–323why, one step back322 with open("test/foo.txt", "rb") as f:323 assert f.read() == b"meh\n"Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 324why, one step back324Merge branch '7.x'David Lordbefore adoption7239794
lines 325–326why, one step back325 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])326 assert "is a file" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 327–328why, one step back327328 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 329why, one step back329 @click.option("-f", type=click.Path(exists=True))Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 330why, one step back330 def showtype(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 331–332why, one step back331 click.echo(f"is_file={os.path.isfile(f)}")332 click.echo(f"is_dir={os.path.isdir(f)}")Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 333–334why, one step back333334 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 335–336why, one step back335 result = runner.invoke(showtype, ["-f", "xxx"])336 assert "does not exist" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 337why, one step back337Merge branch '7.x'David Lordbefore adoption7239794
lines 338–340why, one step back338 result = runner.invoke(showtype, ["-f", "."])339 assert "is_file=False" in result.output340 assert "is_dir=True" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 341–342why, one step back341342 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 343why, one step back343 @click.option("-f", type=click.Path())Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 344why, one step back344 def exists(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 345why, one step back345 click.echo(f"exists={os.path.exists(f)}")Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 346–347why, one step back346347 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 348–349why, one step back348 result = runner.invoke(exists, ["-f", "xxx"])349 assert "exists=False" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 350why, one step back350Merge branch '7.x'David Lordbefore adoption7239794
lines 351–352why, one step back351 result = runner.invoke(exists, ["-f", "."])352 assert "exists=True" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 353–356why, one step back353354355def test_choice_option(runner):356 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 357why, one step back357 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 358–360why, one step back358 def cli(method):359 click.echo(method)360Merge branch '7.x'David Lordbefore adoption7239794
line 361why, one step back361 result = runner.invoke(cli, ["--method=foo"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 362why, one step back362 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 363why, one step back363 assert result.output == "foo\n"Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 364why, one step back364Merge branch '7.x'David Lordbefore adoption7239794
line 365why, one step back365 result = runner.invoke(cli, ["--method=meh"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 366why, one step back366 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 367why, one step back367 assert (Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
lines 368–369why, one step back368 "Invalid value for '--method': 'meh' is not one of 'foo', 'bar', 'baz'."369 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 370why, one step back370 )Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 371why, one step back371Merge branch '7.x'David Lordbefore adoption7239794
lines 372–373why, one step back372 result = runner.invoke(cli, ["--help"])373 assert "--method [foo|bar|baz]" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 374–375why, one step back374375Merge pull request #1273 from 0xDEC0DE/issue/1272David Lordbefore adoptiond15f740
lines 376–388why, one step back376def test_choice_argument(runner):377 @click.command()378 @click.argument("method", type=click.Choice(["foo", "bar", "baz"]))379 def cli(method):380 click.echo(method)381382 result = runner.invoke(cli, ["foo"])383 assert not result.exception384 assert result.output == "foo\n"385386 result = runner.invoke(cli, ["meh"])387 assert result.exit_code == 2388 assert (Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
lines 389–390why, one step back389 "Invalid value for '{foo|bar|baz}': 'meh' is not one of 'foo',"390 " 'bar', 'baz'." in result.outputMerge pull request #1273 from 0xDEC0DE/issue/1272David Lordbefore adoptiond15f740
lines 391–396why, one step back391 )392393 result = runner.invoke(cli, ["--help"])394 assert "{foo|bar|baz}" in result.output395396Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 397–398why, one step back397def test_datetime_option_default(runner):398 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 399why, one step back399 @click.option("--start_date", type=click.DateTime())Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 400why, one step back400 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 401why, one step back401 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 402why, one step back402Merge branch '7.x'David Lordbefore adoption7239794
line 403why, one step back403 result = runner.invoke(cli, ["--start_date=2015-09-29"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 404why, one step back404 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 405why, one step back405 assert result.output == "2015-09-29T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 406why, one step back406Merge branch '7.x'David Lordbefore adoption7239794
line 407why, one step back407 result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 408why, one step back408 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 409why, one step back409 assert result.output == "2015-09-29T09:11:22\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 410why, one step back410Merge branch '7.x'David Lordbefore adoption7239794
line 411why, one step back411 result = runner.invoke(cli, ["--start_date=2015-09"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 412why, one step back412 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 413why, one step back413 assert (Merge pull request #1687 from pallets/multiple-tupleDavid Lordbefore adoptionc067af7
lines 414–415why, one step back414 "Invalid value for '--start_date': '2015-09' does not match the formats"415 " '%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'."Merge branch '7.x'David Lordbefore adoption7239794
line 416why, one step back416 ) in result.outputMerge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 417why, one step back417Merge branch '7.x'David Lordbefore adoption7239794
lines 418–421why, one step back418 result = runner.invoke(cli, ["--help"])419 assert (420 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output421 )Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 422–425why, one step back422423424def test_datetime_option_custom(runner):425 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 426why, one step back426 @click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 427why, one step back427 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 428why, one step back428 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 429why, one step back429Merge branch '7.x'David Lordbefore adoption7239794
line 430why, one step back430 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 431why, one step back431 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 432why, one step back432 assert result.output == "2010-06-05T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 433–434why, one step back433434Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 435–436why, one step back435def test_required_option(runner):436 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 437why, one step back437 @click.option("--foo", required=True)Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 438–442why, one step back438 def cli(foo):439 click.echo(foo)440441 result = runner.invoke(cli, [])442 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 443why, one step back443 assert "Missing option '--foo'" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 444–453why, one step back444445446def test_evaluation_order(runner):447 called = []448449 def memo(ctx, param, value):450 called.append(value)451 return value452453 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 454–460why, one step back454 @click.option("--missing", default="missing", is_eager=False, callback=memo)455 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)456 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)457 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)458 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)459 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)460 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 461–463why, one step back461 def cli(**x):462 pass463Merge branch '7.x'David Lordbefore adoption7239794
lines 464–476why, one step back464 result = runner.invoke(465 cli,466 [467 "--eager-flag2",468 "--eager-flag1",469 "--normal-flag2",470 "--eager-flag3",471 "--normal-flag3",472 "--normal-flag3",473 "--normal-flag1",474 "--normal-flag1",475 ],476 )Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 477–478why, one step back477 assert not result.exception478 assert called == [Merge branch '7.x'David Lordbefore adoption7239794
lines 479–485why, one step back479 "eager2",480 "eager1",481 "eager3",482 "normal2",483 "normal3",484 "normal1",485 "missing",Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 486–490why, one step back486 ]487488489def test_hidden_option(runner):490 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 491why, one step back491 @click.option("--nope", hidden=True)Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 492–494why, one step back492 def cli(nope):493 click.echo(nope)494Merge branch '7.x'David Lordbefore adoption7239794
line 495why, one step back495 result = runner.invoke(cli, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 496why, one step back496 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 497why, one step back497 assert "--nope" not in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 498–508why, one step back498499500def test_hidden_command(runner):501 @click.group()502 def cli():503 pass504505 @cli.command(hidden=True)506 def nope():507 pass508Merge branch '7.x'David Lordbefore adoption7239794
line 509why, one step back509 result = runner.invoke(cli, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 510why, one step back510 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 511why, one step back511 assert "nope" not in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 512–526why, one step back512513514def test_hidden_group(runner):515 @click.group()516 def cli():517 pass518519 @cli.group(hidden=True)520 def subgroup():521 pass522523 @subgroup.command()524 def nope():525 pass526Merge branch '7.x'David Lordbefore adoption7239794
line 527why, one step back527 result = runner.invoke(cli, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 528why, one step back528 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 529–530why, one step back529 assert "subgroup" not in result.output530 assert "nope" not in result.outputMerge pull request #1695 from srafi1/help-summaryAmy Leibefore adoptiona4763ef
lines 531–549why, one step back531532533def test_summary_line(runner):534 @click.group()535 def cli():536 pass537538 @cli.command()539 def cmd():540 """541 Summary line without period542543 Here is a sentence. And here too.544 """545 pass546547 result = runner.invoke(cli, ["--help"])548 assert "Summary line without period" in result.output549 assert "Here is a sentence." not in result.output