test_basic.py
This file
Path
tests/test_basic.py
560 lines · 15.5 KiB · Python
Last changed by
Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
History of this fileTake it
The walk stopped after 200 commits: lines older than 950463b point at it.
Fix typo (#817)scottbeldenbefore adoption950463b
lines 1–3why, one step back1# -*- coding: utf-8 -*-2import os3import uuidMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 4why, one step back4Fix typo (#817)scottbeldenbefore adoption950463b
lines 5–11why, one step back5import click678def test_basic_functionality(runner):9 @click.command()10 def cli():11 """Hello World!"""Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 12why, one step back12 click.echo("I EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
line 13why, one step back13Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 14why, one step back14 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 15why, one step back15 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 16–17why, one step back16 assert "Hello World!" in result.output17 assert "Show this message and exit." in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 18why, one step back18 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 19why, one step back19 assert "I EXECUTED" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 20–22why, one step back2021 result = runner.invoke(cli, [])22 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 23why, one step back23 assert "I EXECUTED" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 24–26why, one step back24 assert result.exit_code == 02526Merge pull request #1481 from pallets/command-reprDavid Lordbefore adoption0fc0a42
lines 27–39why, one step back27def test_repr():28 @click.command()29 def command():30 pass3132 @click.group()33 def group():34 pass3536 @group.command()37 def subcommand():38 pass39Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 40–42why, one step back40 assert repr(command) == "<Command command>"41 assert repr(group) == "<Group group>"42 assert repr(subcommand) == "<Command subcommand>"Merge pull request #1481 from pallets/command-reprDavid Lordbefore adoption0fc0a42
lines 43–44why, one step back4344Fix typo (#817)scottbeldenbefore adoption950463b
lines 45–49why, one step back45def test_return_values():46 @click.command()47 def cli():48 return 4249Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 50why, one step back50 with cli.make_context("foo", []) as ctx:Fix typo (#817)scottbeldenbefore adoption950463b
line 51why, one step back51 rv = cli.invoke(ctx)Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 52why, one step back52 assert rv == 42Fix typo (#817)scottbeldenbefore adoption950463b
lines 53–58why, one step back535455def test_basic_group(runner):56 @click.group()57 def cli():58 """This is the root."""Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 59why, one step back59 click.echo("ROOT EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
lines 60–63why, one step back6061 @cli.command()62 def subcommand():63 """This is a subcommand."""Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 64why, one step back64 click.echo("SUBCOMMAND EXECUTED")Fix typo (#817)scottbeldenbefore adoption950463b
line 65why, one step back65Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 66why, one step back66 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 67why, one step back67 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 68–70why, one step back68 assert "COMMAND [ARGS]..." in result.output69 assert "This is the root" in result.output70 assert "This is a subcommand." in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 71why, one step back71 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 72why, one step back72 assert "ROOT EXECUTED" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 73why, one step back73Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 74why, one step back74 result = runner.invoke(cli, ["subcommand"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 75–76why, one step back75 assert not result.exception76 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 77–78why, one step back77 assert "ROOT EXECUTED" in result.output78 assert "SUBCOMMAND EXECUTED" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 79–82why, one step back798081def test_basic_option(runner):82 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 83why, one step back83 @click.option("--foo", default="no value")Fix typo (#817)scottbeldenbefore adoption950463b
line 84why, one step back84 def cli(foo):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 85why, one step back85 click.echo(u"FOO:[{}]".format(foo))Fix typo (#817)scottbeldenbefore adoption950463b
lines 86–88why, one step back8687 result = runner.invoke(cli, [])88 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 89why, one step back89 assert "FOO:[no value]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 90why, one step back90Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 91why, one step back91 result = runner.invoke(cli, ["--foo=42"])Fix typo (#817)scottbeldenbefore adoption950463b
line 92why, one step back92 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 93why, one step back93 assert "FOO:[42]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 94why, one step back94Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 95why, one step back95 result = runner.invoke(cli, ["--foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 96why, one step back96 assert result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 97why, one step back97 assert "--foo option requires an argument" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 98why, one step back98Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 99why, one step back99 result = runner.invoke(cli, ["--foo="])Fix typo (#817)scottbeldenbefore adoption950463b
line 100why, one step back100 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 101why, one step back101 assert "FOO:[]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 102why, one step back102Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 103why, one step back103 result = runner.invoke(cli, [u"--foo=\N{SNOWMAN}"])Fix typo (#817)scottbeldenbefore adoption950463b
line 104why, one step back104 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 105why, one step back105 assert u"FOO:[\N{SNOWMAN}]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 106–109why, one step back106107108def test_int_option(runner):109 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 110why, one step back110 @click.option("--foo", default=42)Fix typo (#817)scottbeldenbefore adoption950463b
line 111why, one step back111 def cli(foo):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 112why, one step back112 click.echo("FOO:[{}]".format(foo * 2))Fix typo (#817)scottbeldenbefore adoption950463b
lines 113–115why, one step back113114 result = runner.invoke(cli, [])115 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 116why, one step back116 assert "FOO:[84]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 117why, one step back117Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 118why, one step back118 result = runner.invoke(cli, ["--foo=23"])Fix typo (#817)scottbeldenbefore adoption950463b
line 119why, one step back119 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 120why, one step back120 assert "FOO:[46]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 121why, one step back121Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 122why, one step back122 result = runner.invoke(cli, ["--foo=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 123why, one step back123 assert result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 124why, one step back124 assert "Invalid value for '--foo': bar is not a valid integer" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 125–128why, one step back125126127def test_uuid_option(runner):128 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 129–131why, one step back129 @click.option(130 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID131 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 132–133why, one step back132 def cli(u):133 assert type(u) is uuid.UUIDMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 134why, one step back134 click.echo("U:[{}]".format(u))Fix typo (#817)scottbeldenbefore adoption950463b
lines 135–137why, one step back135136 result = runner.invoke(cli, [])137 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 138why, one step back138 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 139why, one step back139Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 140why, one step back140 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])Fix typo (#817)scottbeldenbefore adoption950463b
line 141why, one step back141 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 142why, one step back142 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 143why, one step back143Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 144why, one step back144 result = runner.invoke(cli, ["--u=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 145why, one step back145 assert result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 146why, one step back146 assert "Invalid value for '--u': bar is not a valid UUID value" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 147–150why, one step back147148149def test_float_option(runner):150 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 151why, one step back151 @click.option("--foo", default=42, type=click.FLOAT)Fix typo (#817)scottbeldenbefore adoption950463b
lines 152–153why, one step back152 def cli(foo):153 assert type(foo) is floatMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 154why, one step back154 click.echo("FOO:[{}]".format(foo))Fix typo (#817)scottbeldenbefore adoption950463b
lines 155–157why, one step back155156 result = runner.invoke(cli, [])157 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 158why, one step back158 assert "FOO:[42.0]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 159why, one step back159Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 160why, one step back160 result = runner.invoke(cli, ["--foo=23.5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 161why, one step back161 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 162why, one step back162 assert "FOO:[23.5]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 163why, one step back163Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 164why, one step back164 result = runner.invoke(cli, ["--foo=bar"])Fix typo (#817)scottbeldenbefore adoption950463b
line 165why, one step back165 assert result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 166why, one step back166 assert "Invalid value for '--foo': bar is not a valid float" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 167–170why, one step back167168169def test_boolean_option(runner):170 for default in True, False:Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 171why, one step back171Fix typo (#817)scottbeldenbefore adoption950463b
line 172why, one step back172 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 173why, one step back173 @click.option("--with-foo/--without-foo", default=default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 174–176why, one step back174 def cli(with_foo):175 click.echo(with_foo)176Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 177why, one step back177 result = runner.invoke(cli, ["--with-foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 178why, one step back178 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 179–180why, one step back179 assert result.output == "True\n"180 result = runner.invoke(cli, ["--without-foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 181why, one step back181 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 182why, one step back182 assert result.output == "False\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 183–184why, one step back183 result = runner.invoke(cli, [])184 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 185why, one step back185 assert result.output == "{}\n".format(default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 186–187why, one step back186187 for default in True, False:Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 188why, one step back188Fix typo (#817)scottbeldenbefore adoption950463b
line 189why, one step back189 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 190why, one step back190 @click.option("--flag", is_flag=True, default=default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 191–193why, one step back191 def cli(flag):192 click.echo(flag)193Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 194why, one step back194 result = runner.invoke(cli, ["--flag"])Fix typo (#817)scottbeldenbefore adoption950463b
line 195why, one step back195 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 196why, one step back196 assert result.output == "{}\n".format(not default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 197–198why, one step back197 result = runner.invoke(cli, [])198 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 199why, one step back199 assert result.output == "{}\n".format(default)Fix typo (#817)scottbeldenbefore adoption950463b
lines 200–201why, one step back200201Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
lines 202–203why, one step back202def test_boolean_conversion(runner):203 for default in True, False:Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 204why, one step back204Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 205why, one step back205 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 213why, one step back213 assert result.output == "True\n"Merge pull request #842 from axu2/masterMarkus Unterwaditzerbefore adoption752ff79
line 214why, one step back214Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 back223224Fix typo (#817)scottbeldenbefore adoption950463b
lines 225–226why, one step back225def test_file_option(runner):226 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 227why, one step back227 @click.option("--file", type=click.File("w"))Fix typo (#817)scottbeldenbefore adoption950463b
line 228why, one step back228 def input(file):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 229why, one step back229 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 230–231why, one step back230231 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 232why, one step back232 @click.option("--file", type=click.File("r"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 233–236why, one step back233 def output(file):234 click.echo(file.read())235236 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 237–238why, one step back237 result_in = runner.invoke(input, ["--file=example.txt"])238 result_out = runner.invoke(output, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 239–240why, one step back239240 assert not result_in.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 241why, one step back241 assert result_in.output == ""Fix typo (#817)scottbeldenbefore adoption950463b
line 242why, one step back242 assert not result_out.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 243why, one step back243 assert result_out.output == "Hello World!\n\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 244–249why, one step back244245246def test_file_lazy_mode(runner):247 do_io = False248249 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 250why, one step back250 @click.option("--file", type=click.File("w"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 251–252why, one step back251 def input(file):252 if do_io:Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 253why, one step back253 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 254–255why, one step back254255 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 256why, one step back256 @click.option("--file", type=click.File("r"))Fix typo (#817)scottbeldenbefore adoption950463b
lines 257–260why, one step back257 def output(file):258 pass259260 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 261why, one step back261 os.mkdir("example.txt")Fix typo (#817)scottbeldenbefore adoption950463b
lines 262–263why, one step back262263 do_io = TrueMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 264why, one step back264 result_in = runner.invoke(input, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 265–267why, one step back265 assert result_in.exit_code == 1266267 do_io = FalseMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 268why, one step back268 result_in = runner.invoke(input, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 269–270why, one step back269 assert result_in.exit_code == 0270Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 271why, one step back271 result_out = runner.invoke(output, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 272–274why, one step back272 assert result_out.exception273274 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 275why, one step back275 @click.option("--file", type=click.File("w", lazy=False))Fix typo (#817)scottbeldenbefore adoption950463b
line 276why, one step back276 def input_non_lazy(file):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 277why, one step back277 file.write("Hello World!\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 278–279why, one step back278279 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 280–281why, one step back280 os.mkdir("example.txt")281 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])Fix typo (#817)scottbeldenbefore adoption950463b
line 282why, one step back282 assert result_in.exit_code == 2Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 283–284why, one step back283 assert (284 "Invalid value for '--file': Could not open file: example.txt"Fix typo (#817)scottbeldenbefore adoption950463b
line 285why, one step back285 in result_in.outputMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 286why, one step back286 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 287–290why, one step back287288289def test_path_option(runner):290 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 291why, one step back291 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Fix typo (#817)scottbeldenbefore adoption950463b
line 292why, one step back292 def write_to_dir(o):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 293–294why, one step back293 with open(os.path.join(o, "foo.txt"), "wb") as f:294 f.write(b"meh\n")Fix typo (#817)scottbeldenbefore adoption950463b
lines 295–296why, one step back295296 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 297why, one step back297 os.mkdir("test")Fix typo (#817)scottbeldenbefore adoption950463b
line 298why, one step back298Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 299why, one step back299 result = runner.invoke(write_to_dir, ["-O", "test"])Fix typo (#817)scottbeldenbefore adoption950463b
lines 300–301why, one step back300 assert not result.exception301Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 302–303why, one step back302 with open("test/foo.txt", "rb") as f:303 assert f.read() == b"meh\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 304why, one step back304Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 305–306why, one step back305 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])306 assert "is a file" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 307–308why, one step back307308 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 309why, one step back309 @click.option("-f", type=click.Path(exists=True))Fix typo (#817)scottbeldenbefore adoption950463b
line 310why, one step back310 def showtype(f):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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)))Fix typo (#817)scottbeldenbefore adoption950463b
lines 313–314why, one step back313314 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 315–316why, one step back315 result = runner.invoke(showtype, ["-f", "xxx"])316 assert "does not exist" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 317why, one step back317Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 321–322why, one step back321322 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 323why, one step back323 @click.option("-f", type=click.Path())Fix typo (#817)scottbeldenbefore adoption950463b
line 324why, one step back324 def exists(f):Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 325why, one step back325 click.echo("exists={}".format(os.path.exists(f)))Fix typo (#817)scottbeldenbefore adoption950463b
lines 326–327why, one step back326327 with runner.isolated_filesystem():Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 328–329why, one step back328 result = runner.invoke(exists, ["-f", "xxx"])329 assert "exists=False" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
line 330why, one step back330Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 331–332why, one step back331 result = runner.invoke(exists, ["-f", "."])332 assert "exists=True" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
lines 333–336why, one step back333334335def test_choice_option(runner):336 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 337why, one step back337 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Fix typo (#817)scottbeldenbefore adoption950463b
lines 338–340why, one step back338 def cli(method):339 click.echo(method)340Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 341why, one step back341 result = runner.invoke(cli, ["--method=foo"])Fix typo (#817)scottbeldenbefore adoption950463b
line 342why, one step back342 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 343why, one step back343 assert result.output == "foo\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 344why, one step back344Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 345why, one step back345 result = runner.invoke(cli, ["--method=meh"])Fix typo (#817)scottbeldenbefore adoption950463b
line 346why, one step back346 assert result.exit_code == 2Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 347–350why, one step back347 assert (348 "Invalid value for '--method': invalid choice: meh."349 " (choose from foo, bar, baz)" in result.output350 )Fix typo (#817)scottbeldenbefore adoption950463b
line 351why, one step back351Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 352–353why, one step back352 result = runner.invoke(cli, ["--help"])353 assert "--method [foo|bar|baz]" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 back393394Fix typo (#817)scottbeldenbefore adoption950463b
lines 395–396why, one step back395def test_int_range_option(runner):396 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 397why, one step back397 @click.option("--x", type=click.IntRange(0, 5))Fix typo (#817)scottbeldenbefore adoption950463b
lines 398–400why, one step back398 def cli(x):399 click.echo(x)400Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 401why, one step back401 result = runner.invoke(cli, ["--x=5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 402why, one step back402 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 403why, one step back403 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 404why, one step back404Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 405why, one step back405 result = runner.invoke(cli, ["--x=6"])Fix typo (#817)scottbeldenbefore adoption950463b
line 406why, one step back406 assert result.exit_code == 2Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 407–408why, one step back407 assert (408 "Invalid value for '--x': 6 is not in the valid range of 0 to 5.\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 409why, one step back409 in result.outputMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 410why, one step back410 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 411–412why, one step back411412 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 413why, one step back413 @click.option("--x", type=click.IntRange(0, 5, clamp=True))Fix typo (#817)scottbeldenbefore adoption950463b
lines 414–416why, one step back414 def clamp(x):415 click.echo(x)416Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 417why, one step back417 result = runner.invoke(clamp, ["--x=5"])Fix typo (#817)scottbeldenbefore adoption950463b
line 418why, one step back418 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 419why, one step back419 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 420why, one step back420Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 421why, one step back421 result = runner.invoke(clamp, ["--x=6"])Fix typo (#817)scottbeldenbefore adoption950463b
line 422why, one step back422 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 423why, one step back423 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 424why, one step back424Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 425why, one step back425 result = runner.invoke(clamp, ["--x=-1"])Fix typo (#817)scottbeldenbefore adoption950463b
line 426why, one step back426 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 427why, one step back427 assert result.output == "0\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 428–431why, one step back428429430def test_float_range_option(runner):431 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 432why, one step back432 @click.option("--x", type=click.FloatRange(0, 5))Fix typo (#817)scottbeldenbefore adoption950463b
lines 433–435why, one step back433 def cli(x):434 click.echo(x)435Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 436why, one step back436 result = runner.invoke(cli, ["--x=5.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 437why, one step back437 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 438why, one step back438 assert result.output == "5.0\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 439why, one step back439Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 440why, one step back440 result = runner.invoke(cli, ["--x=6.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 441why, one step back441 assert result.exit_code == 2Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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"Fix typo (#817)scottbeldenbefore adoption950463b
line 444why, one step back444 in result.outputMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 445why, one step back445 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 446–447why, one step back446447 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 448why, one step back448 @click.option("--x", type=click.FloatRange(0, 5, clamp=True))Fix typo (#817)scottbeldenbefore adoption950463b
lines 449–451why, one step back449 def clamp(x):450 click.echo(x)451Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 452why, one step back452 result = runner.invoke(clamp, ["--x=5.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 453why, one step back453 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 454why, one step back454 assert result.output == "5.0\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 455why, one step back455Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 456why, one step back456 result = runner.invoke(clamp, ["--x=6.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 457why, one step back457 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 458why, one step back458 assert result.output == "5\n"Fix typo (#817)scottbeldenbefore adoption950463b
line 459why, one step back459Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 460why, one step back460 result = runner.invoke(clamp, ["--x=-1.0"])Fix typo (#817)scottbeldenbefore adoption950463b
line 461why, one step back461 assert not result.exceptionMerge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 462why, one step back462 assert result.output == "0\n"Fix typo (#817)scottbeldenbefore adoption950463b
lines 463–466why, one step back463464465def test_required_option(runner):466 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 467why, one step back467 @click.option("--foo", required=True)Fix typo (#817)scottbeldenbefore adoption950463b
lines 468–472why, one step back468 def cli(foo):469 click.echo(foo)470471 result = runner.invoke(cli, [])472 assert result.exit_code == 2Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 473why, one step back473 assert "Missing option '--foo'" in result.outputFix typo (#817)scottbeldenbefore adoption950463b
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):Fix typo (#817)scottbeldenbefore adoption950463b
lines 480–483why, one step back480 called.append(value)481 return value482483 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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)Fix typo (#817)scottbeldenbefore adoption950463b
lines 491–493why, one step back491 def cli(**x):492 pass493Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
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 )Fix typo (#817)scottbeldenbefore adoption950463b
lines 507–508why, one step back507 assert not result.exception508 assert called == [Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 509–515why, one step back509 "eager2",510 "eager1",511 "eager3",512 "normal2",513 "normal3",514 "normal1",515 "missing",Fix typo (#817)scottbeldenbefore adoption950463b
lines 516–520why, one step back516 ]517518519def test_hidden_option(runner):520 @click.command()Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 521why, one step back521 @click.option("--nope", hidden=True)Fix typo (#817)scottbeldenbefore adoption950463b
lines 522–524why, one step back522 def cli(nope):523 click.echo(nope)524Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 525why, one step back525 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 526why, one step back526 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 527why, one step back527 assert "--nope" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 539why, one step back539 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 540why, one step back540 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 541why, one step back541 assert "nope" not in result.outputFix typo (#817)scottbeldenbefore adoption950463b
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 pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
line 557why, one step back557 result = runner.invoke(cli, ["--help"])Fix typo (#817)scottbeldenbefore adoption950463b
line 558why, one step back558 assert result.exit_code == 0Merge pull request #1490 from pallets/styleDavid Lordbefore adoption38ba2e6
lines 559–560why, one step back559 assert "subgroup" not in result.output560 assert "nope" not in result.output