test_basic.py
This file
Path
tests/test_basic.py
560 lines · 15.5 KiB · Python
Last changed by
Merge branch '7.x'David Lordbefore adoption7239794
History of this fileTake it
The walk stopped after 200 commits: lines older than 2899795 point at it.
Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 1–3why, one step back1# -*- coding: utf-8 -*-2import os3import uuidMerge branch '7.x'David Lordbefore adoption7239794
line 4why, one step back4Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 5–11why, one step back5import click678def test_basic_functionality(runner):9 @click.command()10 def cli():11 """Hello World!"""Merge branch '7.x'David Lordbefore adoption7239794
line 12why, one step back12 click.echo("I EXECUTED")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 13why, one step back13Merge branch '7.x'David Lordbefore adoption7239794
line 14why, one step back14 result = runner.invoke(cli, ["--help"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 15why, one step back15 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 16–17why, one step back16 assert "Hello World!" in result.output17 assert "Show this message and exit." in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 18why, one step back18 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 19why, one step back19 assert "I EXECUTED" not in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 20–22why, one step back2021 result = runner.invoke(cli, [])22 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 23why, one step back23 assert "I EXECUTED" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 24–26why, one step back24 assert result.exit_code == 02526Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a
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 pass39Merge branch '7.x'David Lordbefore adoption7239794
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 #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a
lines 43–44why, one step back4344Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 45–49why, one step back45def test_return_values():46 @click.command()47 def cli():48 return 4249Merge branch '7.x'David Lordbefore adoption7239794
line 50why, one step back50 with cli.make_context("foo", []) as ctx:Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 51why, one step back51 rv = cli.invoke(ctx)Merge pull request #1445 from tirkarthi/fix-syntax-warningJoshua Bronsonbefore adoption6c454c8
line 52why, one step back52 assert rv == 42Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 53–58why, one step back535455def test_basic_group(runner):56 @click.group()57 def cli():58 """This is the root."""Merge branch '7.x'David Lordbefore adoption7239794
line 59why, one step back59 click.echo("ROOT EXECUTED")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 60–63why, one step back6061 @cli.command()62 def subcommand():63 """This is a subcommand."""Merge branch '7.x'David Lordbefore adoption7239794
line 64why, one step back64 click.echo("SUBCOMMAND EXECUTED")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 65why, one step back65Merge branch '7.x'David Lordbefore adoption7239794
line 66why, one step back66 result = runner.invoke(cli, ["--help"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 67why, one step back67 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
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.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 71why, one step back71 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 72why, one step back72 assert "ROOT EXECUTED" not in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 73why, one step back73Merge branch '7.x'David Lordbefore adoption7239794
line 74why, one step back74 result = runner.invoke(cli, ["subcommand"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 75–76why, one step back75 assert not result.exception76 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 77–78why, one step back77 assert "ROOT EXECUTED" in result.output78 assert "SUBCOMMAND EXECUTED" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 79–82why, one step back798081def test_basic_option(runner):82 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 83why, one step back83 @click.option("--foo", default="no value")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 84why, one step back84 def cli(foo):Merge branch '7.x'David Lordbefore adoption7239794
line 85why, one step back85 click.echo(u"FOO:[{}]".format(foo))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 86–88why, one step back8687 result = runner.invoke(cli, [])88 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 89why, one step back89 assert "FOO:[no value]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 90why, one step back90Merge branch '7.x'David Lordbefore adoption7239794
line 91why, one step back91 result = runner.invoke(cli, ["--foo=42"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 92why, one step back92 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 93why, one step back93 assert "FOO:[42]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 94why, one step back94Merge branch '7.x'David Lordbefore adoption7239794
line 95why, one step back95 result = runner.invoke(cli, ["--foo"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 96why, one step back96 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 97why, one step back97 assert "--foo option requires an argument" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 98why, one step back98Merge branch '7.x'David Lordbefore adoption7239794
line 99why, one step back99 result = runner.invoke(cli, ["--foo="])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 100why, one step back100 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 101why, one step back101 assert "FOO:[]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 102why, one step back102Merge branch '7.x'David Lordbefore adoption7239794
line 103why, one step back103 result = runner.invoke(cli, [u"--foo=\N{SNOWMAN}"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 104why, one step back104 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 105why, one step back105 assert u"FOO:[\N{SNOWMAN}]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 106–109why, one step back106107108def test_int_option(runner):109 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 110why, one step back110 @click.option("--foo", default=42)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 111why, one step back111 def cli(foo):Merge branch '7.x'David Lordbefore adoption7239794
line 112why, one step back112 click.echo("FOO:[{}]".format(foo * 2))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 113–115why, one step back113114 result = runner.invoke(cli, [])115 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 116why, one step back116 assert "FOO:[84]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 117why, one step back117Merge branch '7.x'David Lordbefore adoption7239794
line 118why, one step back118 result = runner.invoke(cli, ["--foo=23"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 119why, one step back119 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 120why, one step back120 assert "FOO:[46]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 121why, one step back121Merge branch '7.x'David Lordbefore adoption7239794
line 122why, one step back122 result = runner.invoke(cli, ["--foo=bar"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 123why, one step back123 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 124why, one step back124 assert "Invalid value for '--foo': bar is not a valid integer" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 125–128why, one step back125126127def test_uuid_option(runner):128 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 129–131why, one step back129 @click.option(130 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID131 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 132–133why, one step back132 def cli(u):133 assert type(u) is uuid.UUIDMerge branch '7.x'David Lordbefore adoption7239794
line 134why, one step back134 click.echo("U:[{}]".format(u))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 135–137why, one step back135136 result = runner.invoke(cli, [])137 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 138why, one step back138 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 139why, one step back139Merge branch '7.x'David Lordbefore adoption7239794
line 140why, one step back140 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 141why, one step back141 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 142why, one step back142 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 143why, one step back143Merge branch '7.x'David Lordbefore adoption7239794
line 144why, one step back144 result = runner.invoke(cli, ["--u=bar"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 145why, one step back145 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 146why, one step back146 assert "Invalid value for '--u': bar is not a valid UUID value" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 147–150why, one step back147148149def test_float_option(runner):150 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 151why, one step back151 @click.option("--foo", default=42, type=click.FLOAT)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 152–153why, one step back152 def cli(foo):153 assert type(foo) is floatMerge branch '7.x'David Lordbefore adoption7239794
line 154why, one step back154 click.echo("FOO:[{}]".format(foo))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 155–157why, one step back155156 result = runner.invoke(cli, [])157 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 158why, one step back158 assert "FOO:[42.0]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 159why, one step back159Merge branch '7.x'David Lordbefore adoption7239794
line 160why, one step back160 result = runner.invoke(cli, ["--foo=23.5"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 161why, one step back161 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 162why, one step back162 assert "FOO:[23.5]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 163why, one step back163Merge branch '7.x'David Lordbefore adoption7239794
line 164why, one step back164 result = runner.invoke(cli, ["--foo=bar"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 165why, one step back165 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 166why, one step back166 assert "Invalid value for '--foo': bar is not a valid float" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 167–170why, one step back167168169def test_boolean_option(runner):170 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 171why, one step back171Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 172why, one step back172 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 173why, one step back173 @click.option("--with-foo/--without-foo", default=default)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 174–176why, one step back174 def cli(with_foo):175 click.echo(with_foo)176Merge branch '7.x'David Lordbefore adoption7239794
line 177why, one step back177 result = runner.invoke(cli, ["--with-foo"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 178why, one step back178 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 179–180why, one step back179 assert result.output == "True\n"180 result = runner.invoke(cli, ["--without-foo"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 181why, one step back181 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 182why, one step back182 assert result.output == "False\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 183–184why, one step back183 result = runner.invoke(cli, [])184 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 185why, one step back185 assert result.output == "{}\n".format(default)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 186–187why, one step back186187 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 188why, one step back188Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 189why, one step back189 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 190why, one step back190 @click.option("--flag", is_flag=True, default=default)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 191–193why, one step back191 def cli(flag):192 click.echo(flag)193Merge branch '7.x'David Lordbefore adoption7239794
line 194why, one step back194 result = runner.invoke(cli, ["--flag"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 195why, one step back195 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 196why, one step back196 assert result.output == "{}\n".format(not default)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 197–198why, one step back197 result = runner.invoke(cli, [])198 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 199why, one step back199 assert result.output == "{}\n".format(default)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
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:Merge branch '7.x'David Lordbefore adoption7239794
line 204why, one step back204Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 205why, one step back205 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
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)209Merge branch '7.x'David Lordbefore adoption7239794
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.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 213why, one step back213 assert result.output == "True\n"Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 214why, one step back214Merge branch '7.x'David Lordbefore adoption7239794
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.exceptionMerge branch '7.x'David Lordbefore adoption7239794
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.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 222why, one step back222 assert result.output == "{}\n".format(default)Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 223–224why, one step back223224Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 225–226why, one step back225def test_file_option(runner):226 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 227why, one step back227 @click.option("--file", type=click.File("w"))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 228why, one step back228 def input(file):Merge branch '7.x'David Lordbefore adoption7239794
line 229why, one step back229 file.write("Hello World!\n")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 230–231why, one step back230231 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 232why, one step back232 @click.option("--file", type=click.File("r"))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 233–236why, one step back233 def output(file):234 click.echo(file.read())235236 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 237–238why, one step back237 result_in = runner.invoke(input, ["--file=example.txt"])238 result_out = runner.invoke(output, ["--file=example.txt"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 239–240why, one step back239240 assert not result_in.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 241why, one step back241 assert result_in.output == ""Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 242why, one step back242 assert not result_out.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 243why, one step back243 assert result_out.output == "Hello World!\n\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 244–249why, one step back244245246def test_file_lazy_mode(runner):247 do_io = False248249 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 250why, one step back250 @click.option("--file", type=click.File("w"))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 251–252why, one step back251 def input(file):252 if do_io:Merge branch '7.x'David Lordbefore adoption7239794
line 253why, one step back253 file.write("Hello World!\n")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 254–255why, one step back254255 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 256why, one step back256 @click.option("--file", type=click.File("r"))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 257–260why, one step back257 def output(file):258 pass259260 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 261why, one step back261 os.mkdir("example.txt")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 262–263why, one step back262263 do_io = TrueMerge branch '7.x'David Lordbefore adoption7239794
line 264why, one step back264 result_in = runner.invoke(input, ["--file=example.txt"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 265–267why, one step back265 assert result_in.exit_code == 1266267 do_io = FalseMerge branch '7.x'David Lordbefore adoption7239794
line 268why, one step back268 result_in = runner.invoke(input, ["--file=example.txt"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 269–270why, one step back269 assert result_in.exit_code == 0270Merge branch '7.x'David Lordbefore adoption7239794
line 271why, one step back271 result_out = runner.invoke(output, ["--file=example.txt"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 272–274why, one step back272 assert result_out.exception273274 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 275why, one step back275 @click.option("--file", type=click.File("w", lazy=False))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 276why, one step back276 def input_non_lazy(file):Merge branch '7.x'David Lordbefore adoption7239794
line 277why, one step back277 file.write("Hello World!\n")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 278–279why, one step back278279 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 280–281why, one step back280 os.mkdir("example.txt")281 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 282why, one step back282 assert result_in.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 283–284why, one step back283 assert (284 "Invalid value for '--file': Could not open file: example.txt"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 285why, one step back285 in result_in.outputMerge branch '7.x'David Lordbefore adoption7239794
line 286why, one step back286 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 287–290why, one step back287288289def test_path_option(runner):290 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 291why, one step back291 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 292why, one step back292 def write_to_dir(o):Merge branch '7.x'David Lordbefore adoption7239794
lines 293–294why, one step back293 with open(os.path.join(o, "foo.txt"), "wb") as f:294 f.write(b"meh\n")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 295–296why, one step back295296 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 297why, one step back297 os.mkdir("test")Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 298why, one step back298Merge branch '7.x'David Lordbefore adoption7239794
line 299why, one step back299 result = runner.invoke(write_to_dir, ["-O", "test"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 300–301why, one step back300 assert not result.exception301Merge branch '7.x'David Lordbefore adoption7239794
lines 302–303why, one step back302 with open("test/foo.txt", "rb") as f:303 assert f.read() == b"meh\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 304why, one step back304Merge branch '7.x'David Lordbefore adoption7239794
lines 305–306why, one step back305 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])306 assert "is a file" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 307–308why, one step back307308 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 309why, one step back309 @click.option("-f", type=click.Path(exists=True))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 310why, one step back310 def showtype(f):Merge branch '7.x'David Lordbefore adoption7239794
lines 311–312why, one step back311 click.echo("is_file={}".format(os.path.isfile(f)))312 click.echo("is_dir={}".format(os.path.isdir(f)))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 313–314why, one step back313314 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 315–316why, one step back315 result = runner.invoke(showtype, ["-f", "xxx"])316 assert "does not exist" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 317why, one step back317Merge branch '7.x'David Lordbefore adoption7239794
lines 318–320why, one step back318 result = runner.invoke(showtype, ["-f", "."])319 assert "is_file=False" in result.output320 assert "is_dir=True" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 321–322why, one step back321322 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 323why, one step back323 @click.option("-f", type=click.Path())Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 324why, one step back324 def exists(f):Merge branch '7.x'David Lordbefore adoption7239794
line 325why, one step back325 click.echo("exists={}".format(os.path.exists(f)))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 326–327why, one step back326327 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 328–329why, one step back328 result = runner.invoke(exists, ["-f", "xxx"])329 assert "exists=False" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 330why, one step back330Merge branch '7.x'David Lordbefore adoption7239794
lines 331–332why, one step back331 result = runner.invoke(exists, ["-f", "."])332 assert "exists=True" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 333–336why, one step back333334335def test_choice_option(runner):336 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 337why, one step back337 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 338–340why, one step back338 def cli(method):339 click.echo(method)340Merge branch '7.x'David Lordbefore adoption7239794
line 341why, one step back341 result = runner.invoke(cli, ["--method=foo"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 342why, one step back342 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 343why, one step back343 assert result.output == "foo\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 344why, one step back344Merge branch '7.x'David Lordbefore adoption7239794
line 345why, one step back345 result = runner.invoke(cli, ["--method=meh"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 346why, one step back346 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 347–350why, one step back347 assert (348 "Invalid value for '--method': invalid choice: meh."349 " (choose from foo, bar, baz)" in result.output350 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 351why, one step back351Merge branch '7.x'David Lordbefore adoption7239794
lines 352–353why, one step back352 result = runner.invoke(cli, ["--help"])353 assert "--method [foo|bar|baz]" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 354–355why, one step back354355Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 356–357why, one step back356def test_datetime_option_default(runner):357 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 358why, one step back358 @click.option("--start_date", type=click.DateTime())Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 359why, one step back359 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 360why, one step back360 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 361why, one step back361Merge branch '7.x'David Lordbefore adoption7239794
line 362why, one step back362 result = runner.invoke(cli, ["--start_date=2015-09-29"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 363why, one step back363 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 364why, one step back364 assert result.output == "2015-09-29T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 365why, one step back365Merge branch '7.x'David Lordbefore adoption7239794
line 366why, one step back366 result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 367why, one step back367 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 368why, one step back368 assert result.output == "2015-09-29T09:11:22\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 369why, one step back369Merge branch '7.x'David Lordbefore adoption7239794
line 370why, one step back370 result = runner.invoke(cli, ["--start_date=2015-09"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 371why, one step back371 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 372–376why, one step back372 assert (373 "Invalid value for '--start_date':"374 " invalid datetime format: 2015-09."375 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"376 ) in result.outputMerge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 377why, one step back377Merge branch '7.x'David Lordbefore adoption7239794
lines 378–381why, one step back378 result = runner.invoke(cli, ["--help"])379 assert (380 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output381 )Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 382–385why, one step back382383384def test_datetime_option_custom(runner):385 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 386why, one step back386 @click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 387why, one step back387 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 388why, one step back388 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 389why, one step back389Merge branch '7.x'David Lordbefore adoption7239794
line 390why, one step back390 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 391why, one step back391 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 392why, one step back392 assert result.output == "2010-06-05T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 393–394why, one step back393394Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 395–396why, one step back395def test_int_range_option(runner):396 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 397why, one step back397 @click.option("--x", type=click.IntRange(0, 5))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 398–400why, one step back398 def cli(x):399 click.echo(x)400Merge branch '7.x'David Lordbefore adoption7239794
line 401why, one step back401 result = runner.invoke(cli, ["--x=5"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 402why, one step back402 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 403why, one step back403 assert result.output == "5\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 404why, one step back404Merge branch '7.x'David Lordbefore adoption7239794
line 405why, one step back405 result = runner.invoke(cli, ["--x=6"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 406why, one step back406 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 407–408why, one step back407 assert (408 "Invalid value for '--x': 6 is not in the valid range of 0 to 5.\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 409why, one step back409 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 410why, one step back410 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 411–412why, one step back411412 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 413why, one step back413 @click.option("--x", type=click.IntRange(0, 5, clamp=True))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 414–416why, one step back414 def clamp(x):415 click.echo(x)416Merge branch '7.x'David Lordbefore adoption7239794
line 417why, one step back417 result = runner.invoke(clamp, ["--x=5"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 418why, one step back418 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 419why, one step back419 assert result.output == "5\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 420why, one step back420Merge branch '7.x'David Lordbefore adoption7239794
line 421why, one step back421 result = runner.invoke(clamp, ["--x=6"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 422why, one step back422 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 423why, one step back423 assert result.output == "5\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 424why, one step back424Merge branch '7.x'David Lordbefore adoption7239794
line 425why, one step back425 result = runner.invoke(clamp, ["--x=-1"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 426why, one step back426 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 427why, one step back427 assert result.output == "0\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 428–431why, one step back428429430def test_float_range_option(runner):431 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 432why, one step back432 @click.option("--x", type=click.FloatRange(0, 5))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 433–435why, one step back433 def cli(x):434 click.echo(x)435Merge branch '7.x'David Lordbefore adoption7239794
line 436why, one step back436 result = runner.invoke(cli, ["--x=5.0"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 437why, one step back437 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 438why, one step back438 assert result.output == "5.0\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 439why, one step back439Merge branch '7.x'David Lordbefore adoption7239794
line 440why, one step back440 result = runner.invoke(cli, ["--x=6.0"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 441why, one step back441 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 442–443why, one step back442 assert (443 "Invalid value for '--x': 6.0 is not in the valid range of 0 to 5.\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 444why, one step back444 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 445why, one step back445 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 446–447why, one step back446447 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 448why, one step back448 @click.option("--x", type=click.FloatRange(0, 5, clamp=True))Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 449–451why, one step back449 def clamp(x):450 click.echo(x)451Merge branch '7.x'David Lordbefore adoption7239794
line 452why, one step back452 result = runner.invoke(clamp, ["--x=5.0"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 453why, one step back453 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 454why, one step back454 assert result.output == "5.0\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 455why, one step back455Merge branch '7.x'David Lordbefore adoption7239794
line 456why, one step back456 result = runner.invoke(clamp, ["--x=6.0"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 457why, one step back457 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 458why, one step back458 assert result.output == "5\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 459why, one step back459Merge branch '7.x'David Lordbefore adoption7239794
line 460why, one step back460 result = runner.invoke(clamp, ["--x=-1.0"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 461why, one step back461 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 462why, one step back462 assert result.output == "0\n"Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 463–466why, one step back463464465def test_required_option(runner):466 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 467why, one step back467 @click.option("--foo", required=True)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 468–472why, one step back468 def cli(foo):469 click.echo(foo)470471 result = runner.invoke(cli, [])472 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 473why, one step back473 assert "Missing option '--foo'" in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 474–478why, one step back474475476def test_evaluation_order(runner):477 called = []478Merge branch '6.x-maintenance'Armin Ronacherbefore adoption7404b06
line 479why, one step back479 def memo(ctx, param, value):Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 480–483why, one step back480 called.append(value)481 return value482483 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 484–490why, one step back484 @click.option("--missing", default="missing", is_eager=False, callback=memo)485 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)486 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)487 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)488 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)489 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)490 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 491–493why, one step back491 def cli(**x):492 pass493Merge branch '7.x'David Lordbefore adoption7239794
lines 494–506why, one step back494 result = runner.invoke(495 cli,496 [497 "--eager-flag2",498 "--eager-flag1",499 "--normal-flag2",500 "--eager-flag3",501 "--normal-flag3",502 "--normal-flag3",503 "--normal-flag1",504 "--normal-flag1",505 ],506 )Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 507–508why, one step back507 assert not result.exception508 assert called == [Merge branch '7.x'David Lordbefore adoption7239794
lines 509–515why, one step back509 "eager2",510 "eager1",511 "eager3",512 "normal2",513 "normal3",514 "normal1",515 "missing",Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 516–520why, one step back516 ]517518519def test_hidden_option(runner):520 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 521why, one step back521 @click.option("--nope", hidden=True)Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 522–524why, one step back522 def cli(nope):523 click.echo(nope)524Merge branch '7.x'David Lordbefore adoption7239794
line 525why, one step back525 result = runner.invoke(cli, ["--help"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 526why, one step back526 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 527why, one step back527 assert "--nope" not in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 528–538why, one step back528529530def test_hidden_command(runner):531 @click.group()532 def cli():533 pass534535 @cli.command(hidden=True)536 def nope():537 pass538Merge branch '7.x'David Lordbefore adoption7239794
line 539why, one step back539 result = runner.invoke(cli, ["--help"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 540why, one step back540 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 541why, one step back541 assert "nope" not in result.outputMerge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
lines 542–556why, one step back542543544def test_hidden_group(runner):545 @click.group()546 def cli():547 pass548549 @cli.group(hidden=True)550 def subgroup():551 pass552553 @subgroup.command()554 def nope():555 pass556Merge branch '7.x'David Lordbefore adoption7239794
line 557why, one step back557 result = runner.invoke(cli, ["--help"])Merge branch 'her0e1c1-fix-secho'Markus Unterwaditzerbefore adoption2899795
line 558why, one step back558 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 559–560why, one step back559 assert "subgroup" not in result.output560 assert "nope" not in result.output