test_chain.py
This file
Path
tests/test_chain.py
229 lines · 5.3 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 81b2fda point at it.
Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 1why, one step back1import sysMerge branch '7.x'David Lordbefore adoption7239794
line 2why, one step back2Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 3–4why, one step back3import pytest4Merge branch '7.x'David Lordbefore adoption7239794
line 5why, one step back5import clickMerge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 6why, one step back6Merge branch '7.x'David Lordbefore adoption7239794
line 7why, one step back7Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 8why, one step back8def debug():Merge branch '7.x'David Lordbefore adoption7239794
line 9why, one step back9 click.echo(Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 10–11why, one step back10 f"{sys._getframe(1).f_code.co_name}"11 f"={'|'.join(click.get_current_context().args)}"Merge branch '7.x'David Lordbefore adoption7239794
line 12why, one step back12 )Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 13–19why, one step back131415def test_basic_chaining(runner):16 @click.group(chain=True)17 def cli():18 pass19Merge branch '7.x'David Lordbefore adoption7239794
line 20why, one step back20 @cli.command("sdist")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 21why, one step back21 def sdist():Merge branch '7.x'David Lordbefore adoption7239794
line 22why, one step back22 click.echo("sdist called")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 23why, one step back23Merge branch '7.x'David Lordbefore adoption7239794
line 24why, one step back24 @cli.command("bdist")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 25why, one step back25 def bdist():Merge branch '7.x'David Lordbefore adoption7239794
line 26why, one step back26 click.echo("bdist called")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 27why, one step back27Merge branch '7.x'David Lordbefore adoption7239794
line 28why, one step back28 result = runner.invoke(cli, ["bdist", "sdist", "bdist"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 29–30why, one step back29 assert not result.exception30 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 31–33why, one step back31 "bdist called",32 "sdist called",33 "bdist called",Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 34–42why, one step back34 ]353637def test_chaining_help(runner):38 @click.group(chain=True)39 def cli():40 """ROOT HELP"""41 pass42Merge branch '7.x'David Lordbefore adoption7239794
line 43why, one step back43 @cli.command("sdist")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 44–45why, one step back44 def sdist():45 """SDIST HELP"""Merge branch '7.x'David Lordbefore adoption7239794
line 46why, one step back46 click.echo("sdist called")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 47why, one step back47Merge branch '7.x'David Lordbefore adoption7239794
line 48why, one step back48 @cli.command("bdist")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 49–50why, one step back49 def bdist():50 """BDIST HELP"""Merge branch '7.x'David Lordbefore adoption7239794
line 51why, one step back51 click.echo("bdist called")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 52why, one step back52Merge branch '7.x'David Lordbefore adoption7239794
line 53why, one step back53 result = runner.invoke(cli, ["--help"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 54why, one step back54 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 55–56why, one step back55 assert "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..." in result.output56 assert "ROOT HELP" in result.outputMerge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 57why, one step back57Merge branch '7.x'David Lordbefore adoption7239794
line 58why, one step back58 result = runner.invoke(cli, ["sdist", "--help"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 59why, one step back59 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 60why, one step back60 assert "SDIST HELP" in result.outputMerge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 61why, one step back61Merge branch '7.x'David Lordbefore adoption7239794
line 62why, one step back62 result = runner.invoke(cli, ["bdist", "--help"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 63why, one step back63 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 64why, one step back64 assert "BDIST HELP" in result.outputMerge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 65why, one step back65Merge branch '7.x'David Lordbefore adoption7239794
line 66why, one step back66 result = runner.invoke(cli, ["bdist", "sdist", "--help"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 67why, one step back67 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 68why, one step back68 assert "SDIST HELP" in result.outputMerge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 69–75why, one step back697071def test_chaining_with_options(runner):72 @click.group(chain=True)73 def cli():74 pass75Merge branch '7.x'David Lordbefore adoption7239794
lines 76–77why, one step back76 @cli.command("sdist")77 @click.option("--format")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 78why, one step back78 def sdist(format):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 79why, one step back79 click.echo(f"sdist called {format}")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 80why, one step back80Merge branch '7.x'David Lordbefore adoption7239794
lines 81–82why, one step back81 @cli.command("bdist")82 @click.option("--format")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 83why, one step back83 def bdist(format):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 84why, one step back84 click.echo(f"bdist called {format}")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 85why, one step back85Merge branch '7.x'David Lordbefore adoption7239794
line 86why, one step back86 result = runner.invoke(cli, ["bdist", "--format=1", "sdist", "--format=2"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 87why, one step back87 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 88why, one step back88 assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 89–95why, one step back899091def test_chaining_with_arguments(runner):92 @click.group(chain=True)93 def cli():94 pass95Merge branch '7.x'David Lordbefore adoption7239794
lines 96–97why, one step back96 @cli.command("sdist")97 @click.argument("format")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 98why, one step back98 def sdist(format):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 99why, one step back99 click.echo(f"sdist called {format}")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 100why, one step back100Merge branch '7.x'David Lordbefore adoption7239794
lines 101–102why, one step back101 @cli.command("bdist")102 @click.argument("format")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 103why, one step back103 def bdist(format):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 104why, one step back104 click.echo(f"bdist called {format}")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 105why, one step back105Merge branch '7.x'David Lordbefore adoption7239794
line 106why, one step back106 result = runner.invoke(cli, ["bdist", "1", "sdist", "2"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 107why, one step back107 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 108why, one step back108 assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 109–112why, one step back109110111def test_pipeline(runner):112 @click.group(chain=True, invoke_without_command=True)Merge branch '7.x'David Lordbefore adoption7239794
line 113why, one step back113 @click.option("-i", "--input", type=click.File("r"))Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 114–118why, one step back114 def cli(input):115 pass116117 @cli.resultcallback()118 def process_pipeline(processors, input):Merge branch '7.x'David Lordbefore adoption7239794
line 119why, one step back119 iterator = (x.rstrip("\r\n") for x in input)Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 120–124why, one step back120 for processor in processors:121 iterator = processor(iterator)122 for item in iterator:123 click.echo(item)124Merge branch '7.x'David Lordbefore adoption7239794
line 125why, one step back125 @cli.command("uppercase")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 126–129why, one step back126 def make_uppercase():127 def processor(iterator):128 for line in iterator:129 yield line.upper()Merge branch '7.x'David Lordbefore adoption7239794
line 130why, one step back130Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 131–132why, one step back131 return processor132Merge branch '7.x'David Lordbefore adoption7239794
line 133why, one step back133 @cli.command("strip")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 134–137why, one step back134 def make_strip():135 def processor(iterator):136 for line in iterator:137 yield line.strip()Merge branch '7.x'David Lordbefore adoption7239794
line 138why, one step back138Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 139–140why, one step back139 return processor140Merge branch '7.x'David Lordbefore adoption7239794
line 141why, one step back141 result = runner.invoke(cli, ["-i", "-"], input="foo\nbar")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 142why, one step back142 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 143why, one step back143 assert result.output.splitlines() == ["foo", "bar"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 144why, one step back144Merge branch '7.x'David Lordbefore adoption7239794
line 145why, one step back145 result = runner.invoke(cli, ["-i", "-", "strip"], input="foo \n bar")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 146why, one step back146 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 147why, one step back147 assert result.output.splitlines() == ["foo", "bar"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 148why, one step back148Merge branch '7.x'David Lordbefore adoption7239794
line 149why, one step back149 result = runner.invoke(cli, ["-i", "-", "strip", "uppercase"], input="foo \n bar")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 150why, one step back150 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 151why, one step back151 assert result.output.splitlines() == ["FOO", "BAR"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 152–170why, one step back152153154def test_args_and_chain(runner):155 @click.group(chain=True)156 def cli():157 debug()158159 @cli.command()160 def a():161 debug()162163 @cli.command()164 def b():165 debug()166167 @cli.command()168 def c():169 debug()170Merge branch '7.x'David Lordbefore adoption7239794
line 171why, one step back171 result = runner.invoke(cli, ["a", "b", "c"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 172why, one step back172 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 173why, one step back173 assert result.output.splitlines() == ["cli=", "a=", "b=", "c="]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 174–177why, one step back174175176def test_multicommand_arg_behavior(runner):177 with pytest.raises(RuntimeError):Merge branch '7.x'David Lordbefore adoption7239794
line 178why, one step back178Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 179why, one step back179 @click.group(chain=True)Merge branch '7.x'David Lordbefore adoption7239794
line 180why, one step back180 @click.argument("forbidden", required=False)Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 181–184why, one step back181 def bad_cli():182 pass183184 with pytest.raises(RuntimeError):Merge branch '7.x'David Lordbefore adoption7239794
line 185why, one step back185Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 186why, one step back186 @click.group(chain=True)Merge branch '7.x'David Lordbefore adoption7239794
line 187why, one step back187 @click.argument("forbidden", nargs=-1)Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 188–191why, one step back188 def bad_cli2():189 pass190191 @click.group(chain=True)Merge branch '7.x'David Lordbefore adoption7239794
line 192why, one step back192 @click.argument("arg")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 193why, one step back193 def cli(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 194why, one step back194 click.echo(f"cli:{arg}")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 195–197why, one step back195196 @cli.command()197 def a():Merge branch '7.x'David Lordbefore adoption7239794
line 198why, one step back198 click.echo("a")Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 199why, one step back199Merge branch '7.x'David Lordbefore adoption7239794
line 200why, one step back200 result = runner.invoke(cli, ["foo", "a"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 201why, one step back201 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 202why, one step back202 assert result.output.splitlines() == ["cli:foo", "a"]Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
lines 203–226why, one step back203204205@pytest.mark.xfail206def test_multicommand_chaining(runner):207 @click.group(chain=True)208 def cli():209 debug()210211 @cli.group()212 def l1a():213 debug()214215 @l1a.command()216 def l2a():217 debug()218219 @l1a.command()220 def l2b():221 debug()222223 @cli.command()224 def l1b():225 debug()226Merge branch '7.x'David Lordbefore adoption7239794
line 227why, one step back227 result = runner.invoke(cli, ["l1a", "l2a", "l1b"])Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda
line 228why, one step back228 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 229why, one step back229 assert result.output.splitlines() == ["cli=", "l1a=", "l2a=", "l1b="]