Skip to content
Myr

Merge pull request #1858 from Glyphack/organize-tests-test-chain

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Replaced group of asserts with pytest parametrize

authored by David Lord · committed by GitHub · parents 5828a16, 57af071 · Browse files · 1 file+28 added−31 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+28 added−31 removed

  • tests:+28 added−31 removed

1 file+28 added−31 removed

modified:tests/test_chain.py+28 added-31 removed
32 unmodified lines
33 "bdist called",34 ]353637@pytest.mark.parametrize(38 ("args", "expect"),39 [40 (["--help"], "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..."),41 (["--help"], "ROOT HELP"),42 (["sdist", "--help"], "SDIST HELP"),43 (["bdist", "--help"], "BDIST HELP"),44 (["bdist", "sdist", "--help"], "SDIST HELP"),45 ],46)37def test_chaining_help(runner):47def test_chaining_help(runner, args, expect):48 @click.group(chain=True)49 def cli():50 """ROOT HELP"""51 pass
7 unmodified lines
59 def bdist():60 """BDIST HELP"""61 click.echo("bdist called")6253 result = runner.invoke(cli, ["--help"])63 result = runner.invoke(cli, args)64 assert not result.exception55 assert "COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]..." in result.output56 assert "ROOT HELP" in result.output65 assert expect in result.output6658 result = runner.invoke(cli, ["sdist", "--help"])59 assert not result.exception60 assert "SDIST HELP" in result.output6762 result = runner.invoke(cli, ["bdist", "--help"])63 assert not result.exception64 assert "BDIST HELP" in result.output6566 result = runner.invoke(cli, ["bdist", "sdist", "--help"])67 assert not result.exception68 assert "SDIST HELP" in result.output697068def test_chaining_with_options(runner):69 @click.group(chain=True)70 def cli():71 pass
51 unmodified lines
123 assert not result.exception124 assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]125126127@pytest.mark.parametrize(128 ("args", "input", "expect"),129 [130 (["-f", "-"], "foo\nbar", ["foo", "bar"]),131 (["-f", "-", "strip"], "foo \n bar", ["foo", "bar"]),132 (["-f", "-", "strip", "uppercase"], "foo \n bar", ["FOO", "BAR"]),133 ],134)130def test_pipeline(runner):135def test_pipeline(runner, args, input, expect):136 @click.group(chain=True, invoke_without_command=True)132 @click.option("-i", "--input", type=click.File("r"))133 def cli(input):137 @click.option("-f", type=click.File("r"))138 def cli(f):139 pass140141 @cli.result_callback()137 def process_pipeline(processors, input):138 iterator = (x.rstrip("\r\n") for x in input)142 def process_pipeline(processors, f):143 iterator = (x.rstrip("\r\n") for x in f)144 for processor in processors:145 iterator = processor(iterator)146 for item in iterator:147 click.echo(item)
13 unmodified lines
161 yield line.strip()162163 return processor164160 result = runner.invoke(cli, ["-i", "-"], input="foo\nbar")165 result = runner.invoke(cli, args, input=input)166 assert not result.exception162 assert result.output.splitlines() == ["foo", "bar"]167 assert result.output.splitlines() == expect168164 result = runner.invoke(cli, ["-i", "-", "strip"], input="foo \n bar")165 assert not result.exception166 assert result.output.splitlines() == ["foo", "bar"]169168 result = runner.invoke(cli, ["-i", "-", "strip", "uppercase"], input="foo \n bar")169 assert not result.exception170 assert result.output.splitlines() == ["FOO", "BAR"]171172170def test_args_and_chain(runner):171 @click.group(chain=True)172 def cli():173 debug()
72 unmodified lines