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
Provenance
- Commit
1c42559- Tree
9168b94- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
5828a16- Parent 2
57af071
1 file changed+28 added−31 removed
modified:tests/test_chain.py+28 added-31 removed
32 unmodified lines33 "bdist called",34 ]35 36 37+@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+)37-def test_chaining_help(runner):47+def test_chaining_help(runner, args, expect):48 @click.group(chain=True)49 def cli():50 """ROOT HELP"""51 pass7 unmodified lines59 def bdist():60 """BDIST HELP"""61 click.echo("bdist called")62 53- 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.output66 58- result = runner.invoke(cli, ["sdist", "--help"])59- assert not result.exception60- assert "SDIST HELP" in result.output67 62- result = runner.invoke(cli, ["bdist", "--help"])63- assert not result.exception64- assert "BDIST HELP" in result.output65-66- result = runner.invoke(cli, ["bdist", "sdist", "--help"])67- assert not result.exception68- assert "SDIST HELP" in result.output69-70-68 def test_chaining_with_options(runner):69 @click.group(chain=True)70 def cli():71 pass51 unmodified lines123 assert not result.exception124 assert result.output.splitlines() == ["bdist called 1", "sdist called 2"]125 126 127+@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+)130-def test_pipeline(runner):135+def 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 pass140 141 @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 lines161 yield line.strip()162 163 return processor164 160- 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() == expect168 164- result = runner.invoke(cli, ["-i", "-", "strip"], input="foo \n bar")165- assert not result.exception166- assert result.output.splitlines() == ["foo", "bar"]169 168- result = runner.invoke(cli, ["-i", "-", "strip", "uppercase"], input="foo \n bar")169- assert not result.exception170- assert result.output.splitlines() == ["FOO", "BAR"]171-172-170 def test_args_and_chain(runner):171 @click.group(chain=True)172 def cli():173 debug()72 unmodified lines