Skip to content
Myr

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 file

Take 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 back
1import sys

Merge branch '7.x'David Lordbefore adoption7239794

line 2why, one step back
2

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 3–4why, one step back
3import pytest
4

Merge branch '7.x'David Lordbefore adoption7239794

line 5why, one step back
5import click

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 6why, one step back
6

Merge branch '7.x'David Lordbefore adoption7239794

line 7why, one step back
7

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 8why, one step back
8def debug():

Merge branch '7.x'David Lordbefore adoption7239794

line 9why, one step back
9 click.echo(

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

lines 10–11why, one step back
10 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 back
12 )

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 13–19why, one step back
13
1415def test_basic_chaining(runner):16 @click.group(chain=True)17 def cli():18 pass19

Merge branch '7.x'David Lordbefore adoption7239794

line 20why, one step back
20 @cli.command("sdist")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 21why, one step back
21 def sdist():

Merge branch '7.x'David Lordbefore adoption7239794

line 22why, one step back
22 click.echo("sdist called")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 23why, one step back
23

Merge branch '7.x'David Lordbefore adoption7239794

line 24why, one step back
24 @cli.command("bdist")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 25why, one step back
25 def bdist():

Merge branch '7.x'David Lordbefore adoption7239794

line 26why, one step back
26 click.echo("bdist called")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 27why, one step back
27

Merge branch '7.x'David Lordbefore adoption7239794

line 28why, one step back
28 result = runner.invoke(cli, ["bdist", "sdist", "bdist"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 29–30why, one step back
29 assert not result.exception
30 assert result.output.splitlines() == [

Merge branch '7.x'David Lordbefore adoption7239794

lines 31–33why, one step back
31 "bdist called",
32 "sdist called",33 "bdist called",

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 34–42why, one step back
34 ]
353637def test_chaining_help(runner):38 @click.group(chain=True)39 def cli():40 """ROOT HELP"""41 pass42

Merge branch '7.x'David Lordbefore adoption7239794

line 43why, one step back
43 @cli.command("sdist")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 44–45why, one step back
44 def sdist():
45 """SDIST HELP"""

Merge branch '7.x'David Lordbefore adoption7239794

line 46why, one step back
46 click.echo("sdist called")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 47why, one step back
47

Merge branch '7.x'David Lordbefore adoption7239794

line 48why, one step back
48 @cli.command("bdist")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 49–50why, one step back
49 def bdist():
50 """BDIST HELP"""

Merge branch '7.x'David Lordbefore adoption7239794

line 51why, one step back
51 click.echo("bdist called")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 52why, one step back
52

Merge branch '7.x'David Lordbefore adoption7239794

line 53why, one step back
53 result = runner.invoke(cli, ["--help"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 54why, one step back
54 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

lines 55–56why, one step back
55 assert "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..." in result.output
56 assert "ROOT HELP" in result.output

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 57why, one step back
57

Merge branch '7.x'David Lordbefore adoption7239794

line 58why, one step back
58 result = runner.invoke(cli, ["sdist", "--help"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 59why, one step back
59 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 60why, one step back
60 assert "SDIST HELP" in result.output

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 61why, one step back
61

Merge branch '7.x'David Lordbefore adoption7239794

line 62why, one step back
62 result = runner.invoke(cli, ["bdist", "--help"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 63why, one step back
63 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 64why, one step back
64 assert "BDIST HELP" in result.output

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 65why, one step back
65

Merge branch '7.x'David Lordbefore adoption7239794

line 66why, one step back
66 result = runner.invoke(cli, ["bdist", "sdist", "--help"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 67why, one step back
67 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 68why, one step back
68 assert "SDIST HELP" in result.output

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 69–75why, one step back
69
7071def test_chaining_with_options(runner):72 @click.group(chain=True)73 def cli():74 pass75

Merge branch '7.x'David Lordbefore adoption7239794

lines 76–77why, one step back
76 @cli.command("sdist")
77 @click.option("--format")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 78why, one step back
78 def sdist(format):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 79why, one step back
79 click.echo(f"sdist called {format}")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 80why, one step back
80

Merge branch '7.x'David Lordbefore adoption7239794

lines 81–82why, one step back
81 @cli.command("bdist")
82 @click.option("--format")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 83why, one step back
83 def bdist(format):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 84why, one step back
84 click.echo(f"bdist called {format}")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 85why, one step back
85

Merge branch '7.x'David Lordbefore adoption7239794

line 86why, one step back
86 result = runner.invoke(cli, ["bdist", "--format=1", "sdist", "--format=2"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 87why, one step back
87 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 88why, one step back
88 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 back
89
9091def test_chaining_with_arguments(runner):92 @click.group(chain=True)93 def cli():94 pass95

Merge branch '7.x'David Lordbefore adoption7239794

lines 96–97why, one step back
96 @cli.command("sdist")
97 @click.argument("format")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 98why, one step back
98 def sdist(format):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 99why, one step back
99 click.echo(f"sdist called {format}")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 100why, one step back
100

Merge branch '7.x'David Lordbefore adoption7239794

lines 101–102why, one step back
101 @cli.command("bdist")
102 @click.argument("format")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 103why, one step back
103 def bdist(format):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 104why, one step back
104 click.echo(f"bdist called {format}")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 105why, one step back
105

Merge branch '7.x'David Lordbefore adoption7239794

line 106why, one step back
106 result = runner.invoke(cli, ["bdist", "1", "sdist", "2"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 107why, one step back
107 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 108why, one step back
108 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 back
109
110111def test_pipeline(runner):112 @click.group(chain=True, invoke_without_command=True)

Merge branch '7.x'David Lordbefore adoption7239794

line 113why, one step back
113 @click.option("-i", "--input", type=click.File("r"))

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 114–118why, one step back
114 def cli(input):
115 pass116117 @cli.resultcallback()118 def process_pipeline(processors, input):

Merge branch '7.x'David Lordbefore adoption7239794

line 119why, one step back
119 iterator = (x.rstrip("\r\n") for x in input)

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 120–124why, one step back
120 for processor in processors:
121 iterator = processor(iterator)122 for item in iterator:123 click.echo(item)124

Merge branch '7.x'David Lordbefore adoption7239794

line 125why, one step back
125 @cli.command("uppercase")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 126–129why, one step back
126 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 back
130

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 131–132why, one step back
131 return processor
132

Merge branch '7.x'David Lordbefore adoption7239794

line 133why, one step back
133 @cli.command("strip")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 134–137why, one step back
134 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 back
138

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 139–140why, one step back
139 return processor
140

Merge branch '7.x'David Lordbefore adoption7239794

line 141why, one step back
141 result = runner.invoke(cli, ["-i", "-"], input="foo\nbar")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 142why, one step back
142 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 143why, one step back
143 assert result.output.splitlines() == ["foo", "bar"]

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 144why, one step back
144

Merge branch '7.x'David Lordbefore adoption7239794

line 145why, one step back
145 result = runner.invoke(cli, ["-i", "-", "strip"], input="foo \n bar")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 146why, one step back
146 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 147why, one step back
147 assert result.output.splitlines() == ["foo", "bar"]

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 148why, one step back
148

Merge branch '7.x'David Lordbefore adoption7239794

line 149why, one step back
149 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 back
150 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 151why, one step back
151 assert result.output.splitlines() == ["FOO", "BAR"]

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 152–170why, one step back
152
153154def 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()170

Merge branch '7.x'David Lordbefore adoption7239794

line 171why, one step back
171 result = runner.invoke(cli, ["a", "b", "c"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 172why, one step back
172 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 173why, one step back
173 assert result.output.splitlines() == ["cli=", "a=", "b=", "c="]

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 174–177why, one step back
174
175176def test_multicommand_arg_behavior(runner):177 with pytest.raises(RuntimeError):

Merge branch '7.x'David Lordbefore adoption7239794

line 178why, one step back
178

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 179why, one step back
179 @click.group(chain=True)

Merge branch '7.x'David Lordbefore adoption7239794

line 180why, one step back
180 @click.argument("forbidden", required=False)

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 181–184why, one step back
181 def bad_cli():
182 pass183184 with pytest.raises(RuntimeError):

Merge branch '7.x'David Lordbefore adoption7239794

line 185why, one step back
185

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 186why, one step back
186 @click.group(chain=True)

Merge branch '7.x'David Lordbefore adoption7239794

line 187why, one step back
187 @click.argument("forbidden", nargs=-1)

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 188–191why, one step back
188 def bad_cli2():
189 pass190191 @click.group(chain=True)

Merge branch '7.x'David Lordbefore adoption7239794

line 192why, one step back
192 @click.argument("arg")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 193why, one step back
193 def cli(arg):

Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9

line 194why, one step back
194 click.echo(f"cli:{arg}")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 195–197why, one step back
195
196 @cli.command()197 def a():

Merge branch '7.x'David Lordbefore adoption7239794

line 198why, one step back
198 click.echo("a")

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 199why, one step back
199

Merge branch '7.x'David Lordbefore adoption7239794

line 200why, one step back
200 result = runner.invoke(cli, ["foo", "a"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 201why, one step back
201 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 202why, one step back
202 assert result.output.splitlines() == ["cli:foo", "a"]

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

lines 203–226why, one step back
203
204205@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()226

Merge branch '7.x'David Lordbefore adoption7239794

line 227why, one step back
227 result = runner.invoke(cli, ["l1a", "l2a", "l1b"])

Merge pull request #801 from pombredanne/patch-3David Lordbefore adoption81b2fda

line 228why, one step back
228 assert not result.exception

Merge branch '7.x'David Lordbefore adoption7239794

line 229why, one step back
229 assert result.output.splitlines() == ["cli=", "l1a=", "l2a=", "l1b="]