test_basic.py
This file
Path
tests/test_basic.py
559 lines · 15.4 KiB · Python
Last changed by
Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
History of this fileTake it
The walk stopped after 200 commits: lines older than d5cddb9 point at it.
Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 1–2why, one step back1import os2import uuidMerge branch '7.x'David Lordbefore adoption7239794
line 3why, one step back3Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 4–10why, one step back4import click567def test_basic_functionality(runner):8 @click.command()9 def cli():10 """Hello World!"""Merge branch '7.x'David Lordbefore adoption7239794
line 11why, one step back11 click.echo("I EXECUTED")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 12why, one step back12Merge branch '7.x'David Lordbefore adoption7239794
line 13why, one step back13 result = runner.invoke(cli, ["--help"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 14why, one step back14 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 15–16why, one step back15 assert "Hello World!" in result.output16 assert "Show this message and exit." in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 17why, one step back17 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 18why, one step back18 assert "I EXECUTED" not in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 19–21why, one step back1920 result = runner.invoke(cli, [])21 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 22why, one step back22 assert "I EXECUTED" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 23–25why, one step back23 assert result.exit_code == 02425Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a
lines 26–38why, one step back26def test_repr():27 @click.command()28 def command():29 pass3031 @click.group()32 def group():33 pass3435 @group.command()36 def subcommand():37 pass38Merge branch '7.x'David Lordbefore adoption7239794
lines 39–41why, one step back39 assert repr(command) == "<Command command>"40 assert repr(group) == "<Group group>"41 assert repr(subcommand) == "<Command subcommand>"Merge pull request #1295 from jzengg/issue-1267-add-name-to-command-reprDavid Lordbefore adoptione6eac0a
lines 42–43why, one step back4243Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 44–48why, one step back44def test_return_values():45 @click.command()46 def cli():47 return 4248Merge branch '7.x'David Lordbefore adoption7239794
line 49why, one step back49 with cli.make_context("foo", []) as ctx:Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 50why, one step back50 rv = cli.invoke(ctx)Merge pull request #1445 from tirkarthi/fix-syntax-warningJoshua Bronsonbefore adoption6c454c8
line 51why, one step back51 assert rv == 42Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 52–57why, one step back525354def test_basic_group(runner):55 @click.group()56 def cli():57 """This is the root."""Merge branch '7.x'David Lordbefore adoption7239794
line 58why, one step back58 click.echo("ROOT EXECUTED")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 59–62why, one step back5960 @cli.command()61 def subcommand():62 """This is a subcommand."""Merge branch '7.x'David Lordbefore adoption7239794
line 63why, one step back63 click.echo("SUBCOMMAND EXECUTED")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 64why, one step back64Merge branch '7.x'David Lordbefore adoption7239794
line 65why, one step back65 result = runner.invoke(cli, ["--help"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 66why, one step back66 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 67–69why, one step back67 assert "COMMAND [ARGS]..." in result.output68 assert "This is the root" in result.output69 assert "This is a subcommand." in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 70why, one step back70 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 71why, one step back71 assert "ROOT EXECUTED" not in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 72why, one step back72Merge branch '7.x'David Lordbefore adoption7239794
line 73why, one step back73 result = runner.invoke(cli, ["subcommand"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 74–75why, one step back74 assert not result.exception75 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 76–77why, one step back76 assert "ROOT EXECUTED" in result.output77 assert "SUBCOMMAND EXECUTED" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 78–81why, one step back787980def test_basic_option(runner):81 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 82why, one step back82 @click.option("--foo", default="no value")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 83why, one step back83 def cli(foo):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 84why, one step back84 click.echo(f"FOO:[{foo}]")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 85–87why, one step back8586 result = runner.invoke(cli, [])87 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 88why, one step back88 assert "FOO:[no value]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 89why, one step back89Merge branch '7.x'David Lordbefore adoption7239794
line 90why, one step back90 result = runner.invoke(cli, ["--foo=42"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 91why, one step back91 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 92why, one step back92 assert "FOO:[42]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 93why, one step back93Merge branch '7.x'David Lordbefore adoption7239794
line 94why, one step back94 result = runner.invoke(cli, ["--foo"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 95why, one step back95 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 96why, one step back96 assert "--foo option requires an argument" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 97why, one step back97Merge branch '7.x'David Lordbefore adoption7239794
line 98why, one step back98 result = runner.invoke(cli, ["--foo="])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 99why, one step back99 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 100why, one step back100 assert "FOO:[]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 101why, one step back101Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 102why, one step back102 result = runner.invoke(cli, ["--foo=\N{SNOWMAN}"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 103why, one step back103 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 104why, one step back104 assert "FOO:[\N{SNOWMAN}]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 105–108why, one step back105106107def test_int_option(runner):108 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 109why, one step back109 @click.option("--foo", default=42)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
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 * 2}]")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
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:[84]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 116why, one step back116Merge branch '7.x'David Lordbefore adoption7239794
line 117why, one step back117 result = runner.invoke(cli, ["--foo=23"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 118why, one step back118 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 119why, one step back119 assert "FOO:[46]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 120why, one step back120Merge branch '7.x'David Lordbefore adoption7239794
line 121why, one step back121 result = runner.invoke(cli, ["--foo=bar"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 122why, one step back122 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 123why, one step back123 assert "Invalid value for '--foo': bar is not a valid integer" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 124–127why, one step back124125126def test_uuid_option(runner):127 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 128–130why, one step back128 @click.option(129 "--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID130 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 131–132why, one step back131 def cli(u):132 assert type(u) is uuid.UUIDMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 133why, one step back133 click.echo(f"U:[{u}]")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 134–136why, one step back134135 result = runner.invoke(cli, [])136 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 137why, one step back137 assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 138why, one step back138Merge branch '7.x'David Lordbefore adoption7239794
line 139why, one step back139 result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 140why, one step back140 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 141why, one step back141 assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 142why, one step back142Merge branch '7.x'David Lordbefore adoption7239794
line 143why, one step back143 result = runner.invoke(cli, ["--u=bar"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 144why, one step back144 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 145why, one step back145 assert "Invalid value for '--u': bar is not a valid UUID value" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 146–149why, one step back146147148def test_float_option(runner):149 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 150why, one step back150 @click.option("--foo", default=42, type=click.FLOAT)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 151–152why, one step back151 def cli(foo):152 assert type(foo) is floatMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 153why, one step back153 click.echo(f"FOO:[{foo}]")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 154–156why, one step back154155 result = runner.invoke(cli, [])156 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 157why, one step back157 assert "FOO:[42.0]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 158why, one step back158Merge branch '7.x'David Lordbefore adoption7239794
line 159why, one step back159 result = runner.invoke(cli, ["--foo=23.5"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 160why, one step back160 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 161why, one step back161 assert "FOO:[23.5]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 162why, one step back162Merge branch '7.x'David Lordbefore adoption7239794
line 163why, one step back163 result = runner.invoke(cli, ["--foo=bar"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 164why, one step back164 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 165why, one step back165 assert "Invalid value for '--foo': bar is not a valid float" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 166–169why, one step back166167168def test_boolean_option(runner):169 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 170why, one step back170Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 171why, one step back171 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 172why, one step back172 @click.option("--with-foo/--without-foo", default=default)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 173–175why, one step back173 def cli(with_foo):174 click.echo(with_foo)175Merge branch '7.x'David Lordbefore adoption7239794
line 176why, one step back176 result = runner.invoke(cli, ["--with-foo"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 177why, one step back177 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 178–179why, one step back178 assert result.output == "True\n"179 result = runner.invoke(cli, ["--without-foo"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 180why, one step back180 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 181why, one step back181 assert result.output == "False\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 182–183why, one step back182 result = runner.invoke(cli, [])183 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 184why, one step back184 assert result.output == f"{default}\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 185–186why, one step back185186 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 187why, one step back187Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 188why, one step back188 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 189why, one step back189 @click.option("--flag", is_flag=True, default=default)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 190–192why, one step back190 def cli(flag):191 click.echo(flag)192Merge branch '7.x'David Lordbefore adoption7239794
line 193why, one step back193 result = runner.invoke(cli, ["--flag"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 194why, one step back194 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 195why, one step back195 assert result.output == f"{not default}\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 196–197why, one step back196 result = runner.invoke(cli, [])197 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 198why, one step back198 assert result.output == f"{default}\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 199–202why, one step back199200201def test_boolean_conversion(runner):202 for default in True, False:Merge branch '7.x'David Lordbefore adoption7239794
line 203why, one step back203Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 204why, one step back204 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 205why, one step back205 @click.option("--flag", default=default, type=bool)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 206–208why, one step back206 def cli(flag):207 click.echo(flag)208Merge branch '7.x'David Lordbefore adoption7239794
lines 209–210why, one step back209 for value in "true", "t", "1", "yes", "y":210 result = runner.invoke(cli, ["--flag", value])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 211why, one step back211 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 212why, one step back212 assert result.output == "True\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 213why, one step back213Merge branch '7.x'David Lordbefore adoption7239794
lines 214–215why, one step back214 for value in "false", "f", "0", "no", "n":215 result = runner.invoke(cli, ["--flag", value])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 216why, one step back216 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 217why, one step back217 assert result.output == "False\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 218–220why, one step back218219 result = runner.invoke(cli, [])220 assert not result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 221why, one step back221 assert result.output == f"{default}\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 222–225why, one step back222223224def test_file_option(runner):225 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 226why, one step back226 @click.option("--file", type=click.File("w"))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 227why, one step back227 def input(file):Merge branch '7.x'David Lordbefore adoption7239794
line 228why, one step back228 file.write("Hello World!\n")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 229–230why, one step back229230 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 231why, one step back231 @click.option("--file", type=click.File("r"))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 232–235why, one step back232 def output(file):233 click.echo(file.read())234235 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 236–237why, one step back236 result_in = runner.invoke(input, ["--file=example.txt"])237 result_out = runner.invoke(output, ["--file=example.txt"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 238–239why, one step back238239 assert not result_in.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 240why, one step back240 assert result_in.output == ""Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 241why, one step back241 assert not result_out.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 242why, one step back242 assert result_out.output == "Hello World!\n\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 243–248why, one step back243244245def test_file_lazy_mode(runner):246 do_io = False247248 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 249why, one step back249 @click.option("--file", type=click.File("w"))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 250–251why, one step back250 def input(file):251 if do_io:Merge branch '7.x'David Lordbefore adoption7239794
line 252why, one step back252 file.write("Hello World!\n")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
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"))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 256–259why, one step back256 def output(file):257 pass258259 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 260why, one step back260 os.mkdir("example.txt")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 261–262why, one step back261262 do_io = TrueMerge branch '7.x'David Lordbefore adoption7239794
line 263why, one step back263 result_in = runner.invoke(input, ["--file=example.txt"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 264–266why, one step back264 assert result_in.exit_code == 1265266 do_io = FalseMerge branch '7.x'David Lordbefore adoption7239794
line 267why, one step back267 result_in = runner.invoke(input, ["--file=example.txt"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 268–269why, one step back268 assert result_in.exit_code == 0269Merge branch '7.x'David Lordbefore adoption7239794
line 270why, one step back270 result_out = runner.invoke(output, ["--file=example.txt"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 271–273why, one step back271 assert result_out.exception272273 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 274why, one step back274 @click.option("--file", type=click.File("w", lazy=False))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 275why, one step back275 def input_non_lazy(file):Merge branch '7.x'David Lordbefore adoption7239794
line 276why, one step back276 file.write("Hello World!\n")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 277–278why, one step back277278 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 279–280why, one step back279 os.mkdir("example.txt")280 result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 281why, one step back281 assert result_in.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 282–283why, one step back282 assert (283 "Invalid value for '--file': Could not open file: example.txt"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 284why, one step back284 in result_in.outputMerge branch '7.x'David Lordbefore adoption7239794
line 285why, one step back285 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 286–289why, one step back286287288def test_path_option(runner):289 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 290why, one step back290 @click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 291why, one step back291 def write_to_dir(o):Merge branch '7.x'David Lordbefore adoption7239794
lines 292–293why, one step back292 with open(os.path.join(o, "foo.txt"), "wb") as f:293 f.write(b"meh\n")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 294–295why, one step back294295 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
line 296why, one step back296 os.mkdir("test")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 297why, one step back297Merge branch '7.x'David Lordbefore adoption7239794
line 298why, one step back298 result = runner.invoke(write_to_dir, ["-O", "test"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 299–300why, one step back299 assert not result.exception300Merge branch '7.x'David Lordbefore adoption7239794
lines 301–302why, one step back301 with open("test/foo.txt", "rb") as f:302 assert f.read() == b"meh\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 303why, one step back303Merge branch '7.x'David Lordbefore adoption7239794
lines 304–305why, one step back304 result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])305 assert "is a file" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 306–307why, one step back306307 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 308why, one step back308 @click.option("-f", type=click.Path(exists=True))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 309why, one step back309 def showtype(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 310–311why, one step back310 click.echo(f"is_file={os.path.isfile(f)}")311 click.echo(f"is_dir={os.path.isdir(f)}")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 312–313why, one step back312313 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 314–315why, one step back314 result = runner.invoke(showtype, ["-f", "xxx"])315 assert "does not exist" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 316why, one step back316Merge branch '7.x'David Lordbefore adoption7239794
lines 317–319why, one step back317 result = runner.invoke(showtype, ["-f", "."])318 assert "is_file=False" in result.output319 assert "is_dir=True" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 320–321why, one step back320321 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 322why, one step back322 @click.option("-f", type=click.Path())Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 323why, one step back323 def exists(f):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 324why, one step back324 click.echo(f"exists={os.path.exists(f)}")Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 325–326why, one step back325326 with runner.isolated_filesystem():Merge branch '7.x'David Lordbefore adoption7239794
lines 327–328why, one step back327 result = runner.invoke(exists, ["-f", "xxx"])328 assert "exists=False" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 329why, one step back329Merge branch '7.x'David Lordbefore adoption7239794
lines 330–331why, one step back330 result = runner.invoke(exists, ["-f", "."])331 assert "exists=True" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 332–335why, one step back332333334def test_choice_option(runner):335 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 336why, one step back336 @click.option("--method", type=click.Choice(["foo", "bar", "baz"]))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 337–339why, one step back337 def cli(method):338 click.echo(method)339Merge branch '7.x'David Lordbefore adoption7239794
line 340why, one step back340 result = runner.invoke(cli, ["--method=foo"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 341why, one step back341 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 342why, one step back342 assert result.output == "foo\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 343why, one step back343Merge branch '7.x'David Lordbefore adoption7239794
line 344why, one step back344 result = runner.invoke(cli, ["--method=meh"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 345why, one step back345 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 346–349why, one step back346 assert (347 "Invalid value for '--method': invalid choice: meh."348 " (choose from foo, bar, baz)" in result.output349 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 350why, one step back350Merge branch '7.x'David Lordbefore adoption7239794
lines 351–352why, one step back351 result = runner.invoke(cli, ["--help"])352 assert "--method [foo|bar|baz]" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 353–354why, one step back353354Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 355–356why, one step back355def test_datetime_option_default(runner):356 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 357why, one step back357 @click.option("--start_date", type=click.DateTime())Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 358why, one step back358 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 359why, one step back359 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 360why, one step back360Merge branch '7.x'David Lordbefore adoption7239794
line 361why, one step back361 result = runner.invoke(cli, ["--start_date=2015-09-29"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 362why, one step back362 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 363why, one step back363 assert result.output == "2015-09-29T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 364why, one step back364Merge branch '7.x'David Lordbefore adoption7239794
line 365why, one step back365 result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 366why, one step back366 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 367why, one step back367 assert result.output == "2015-09-29T09:11:22\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 368why, one step back368Merge branch '7.x'David Lordbefore adoption7239794
line 369why, one step back369 result = runner.invoke(cli, ["--start_date=2015-09"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 370why, one step back370 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 371–375why, one step back371 assert (372 "Invalid value for '--start_date':"373 " invalid datetime format: 2015-09."374 " (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"375 ) in result.outputMerge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 376why, one step back376Merge branch '7.x'David Lordbefore adoption7239794
lines 377–380why, one step back377 result = runner.invoke(cli, ["--help"])378 assert (379 "--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output380 )Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 381–384why, one step back381382383def test_datetime_option_custom(runner):384 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 385why, one step back385 @click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 386why, one step back386 def cli(start_date):Merge branch '7.x'David Lordbefore adoption7239794
line 387why, one step back387 click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 388why, one step back388Merge branch '7.x'David Lordbefore adoption7239794
line 389why, one step back389 result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
line 390why, one step back390 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 391why, one step back391 assert result.output == "2010-06-05T00:00:00\n"Merge pull request #1099 from sirosen/type-datetimeDavid Lordbefore adoption2c622ee
lines 392–393why, one step back392393Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 394–395why, one step back394def test_int_range_option(runner):395 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 396why, one step back396 @click.option("--x", type=click.IntRange(0, 5))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 397–399why, one step back397 def cli(x):398 click.echo(x)399Merge branch '7.x'David Lordbefore adoption7239794
line 400why, one step back400 result = runner.invoke(cli, ["--x=5"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 401why, one step back401 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 402why, one step back402 assert result.output == "5\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 403why, one step back403Merge branch '7.x'David Lordbefore adoption7239794
line 404why, one step back404 result = runner.invoke(cli, ["--x=6"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 405why, one step back405 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 406–407why, one step back406 assert (407 "Invalid value for '--x': 6 is not in the valid range of 0 to 5.\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 408why, one step back408 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 409why, one step back409 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 410–411why, one step back410411 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 412why, one step back412 @click.option("--x", type=click.IntRange(0, 5, clamp=True))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 413–415why, one step back413 def clamp(x):414 click.echo(x)415Merge branch '7.x'David Lordbefore adoption7239794
line 416why, one step back416 result = runner.invoke(clamp, ["--x=5"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 417why, one step back417 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 418why, one step back418 assert result.output == "5\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 419why, one step back419Merge branch '7.x'David Lordbefore adoption7239794
line 420why, one step back420 result = runner.invoke(clamp, ["--x=6"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 421why, one step back421 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 422why, one step back422 assert result.output == "5\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 423why, one step back423Merge branch '7.x'David Lordbefore adoption7239794
line 424why, one step back424 result = runner.invoke(clamp, ["--x=-1"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 425why, one step back425 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 426why, one step back426 assert result.output == "0\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 427–430why, one step back427428429def test_float_range_option(runner):430 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 431why, one step back431 @click.option("--x", type=click.FloatRange(0, 5))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 432–434why, one step back432 def cli(x):433 click.echo(x)434Merge branch '7.x'David Lordbefore adoption7239794
line 435why, one step back435 result = runner.invoke(cli, ["--x=5.0"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 436why, one step back436 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 437why, one step back437 assert result.output == "5.0\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 438why, one step back438Merge branch '7.x'David Lordbefore adoption7239794
line 439why, one step back439 result = runner.invoke(cli, ["--x=6.0"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 440why, one step back440 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 441–442why, one step back441 assert (442 "Invalid value for '--x': 6.0 is not in the valid range of 0 to 5.\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 443why, one step back443 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 444why, one step back444 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 445–446why, one step back445446 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 447why, one step back447 @click.option("--x", type=click.FloatRange(0, 5, clamp=True))Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 448–450why, one step back448 def clamp(x):449 click.echo(x)450Merge branch '7.x'David Lordbefore adoption7239794
line 451why, one step back451 result = runner.invoke(clamp, ["--x=5.0"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 452why, one step back452 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 453why, one step back453 assert result.output == "5.0\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 454why, one step back454Merge branch '7.x'David Lordbefore adoption7239794
line 455why, one step back455 result = runner.invoke(clamp, ["--x=6.0"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 456why, one step back456 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 457why, one step back457 assert result.output == "5\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 458why, one step back458Merge branch '7.x'David Lordbefore adoption7239794
line 459why, one step back459 result = runner.invoke(clamp, ["--x=-1.0"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 460why, one step back460 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 461why, one step back461 assert result.output == "0\n"Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 462–465why, one step back462463464def test_required_option(runner):465 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 466why, one step back466 @click.option("--foo", required=True)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 467–471why, one step back467 def cli(foo):468 click.echo(foo)469470 result = runner.invoke(cli, [])471 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
line 472why, one step back472 assert "Missing option '--foo'" in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 473–482why, one step back473474475def test_evaluation_order(runner):476 called = []477478 def memo(ctx, param, value):479 called.append(value)480 return value481482 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 483–489why, one step back483 @click.option("--missing", default="missing", is_eager=False, callback=memo)484 @click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)485 @click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)486 @click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)487 @click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)488 @click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)489 @click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 490–492why, one step back490 def cli(**x):491 pass492Merge branch '7.x'David Lordbefore adoption7239794
lines 493–505why, one step back493 result = runner.invoke(494 cli,495 [496 "--eager-flag2",497 "--eager-flag1",498 "--normal-flag2",499 "--eager-flag3",500 "--normal-flag3",501 "--normal-flag3",502 "--normal-flag1",503 "--normal-flag1",504 ],505 )Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 506–507why, one step back506 assert not result.exception507 assert called == [Merge branch '7.x'David Lordbefore adoption7239794
lines 508–514why, one step back508 "eager2",509 "eager1",510 "eager3",511 "normal2",512 "normal3",513 "normal1",514 "missing",Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 515–519why, one step back515 ]516517518def test_hidden_option(runner):519 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 520why, one step back520 @click.option("--nope", hidden=True)Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 521–523why, one step back521 def cli(nope):522 click.echo(nope)523Merge branch '7.x'David Lordbefore adoption7239794
line 524why, one step back524 result = runner.invoke(cli, ["--help"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 525why, one step back525 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 526why, one step back526 assert "--nope" not in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 527–537why, one step back527528529def test_hidden_command(runner):530 @click.group()531 def cli():532 pass533534 @cli.command(hidden=True)535 def nope():536 pass537Merge branch '7.x'David Lordbefore adoption7239794
line 538why, one step back538 result = runner.invoke(cli, ["--help"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 539why, one step back539 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 540why, one step back540 assert "nope" not in result.outputEscape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
lines 541–555why, one step back541542543def test_hidden_group(runner):544 @click.group()545 def cli():546 pass547548 @cli.group(hidden=True)549 def subgroup():550 pass551552 @subgroup.command()553 def nope():554 pass555Merge branch '7.x'David Lordbefore adoption7239794
line 556why, one step back556 result = runner.invoke(cli, ["--help"])Escape Sequences with r'' (#807)Cooper Leesbefore adoptiond5cddb9
line 557why, one step back557 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 558–559why, one step back558 assert "subgroup" not in result.output559 assert "nope" not in result.output