Merge pull request #1873 from israteneda/organize-command-tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by GitHub · parents 6ef3340, c27e81e · Browse files · 1 file·+24 added−38 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+24 added−38 removed
- tests:+24 added−38 removed
Provenance
- Commit
bf8c03e- Tree
2890338- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
6ef3340- Parent 2
c27e81e
1 file changed+24 added−38 removed
modified:tests/test_commands.py+24 added-38 removed
1 import re2 3+import pytest4+5 import click6 7 8 def test_other_command_invoke(runner):111 unmodified lines120 assert not result.exception121 assert result.output == "changed\n"122 123 124+@pytest.mark.parametrize(125+ ("args", "exit_code", "expect"),126+ [127+ (["obj1"], 2, "Error: Missing command."),128+ (["obj1", "--help"], 0, "Show this message and exit."),129+ (["obj1", "move"], 0, "obj=obj1\nmove\n"),130+ ([], 0, "Show this message and exit."),131+ ],132+)122-def test_group_with_args(runner):133+def test_group_with_args(runner, args, exit_code, expect):134 @click.group()135 @click.argument("obj")136 def cli(obj):137 click.echo(f"obj={obj}")1 unmodified line139 @cli.command()140 def move():141 click.echo("move")142 132- result = runner.invoke(cli, [])133- assert result.exit_code == 0134- assert "Show this message and exit." in result.output143+ result = runner.invoke(cli, args)144+ assert result.exit_code == exit_code145+ assert expect in result.output146 136- result = runner.invoke(cli, ["obj1"])137- assert result.exit_code == 2138- assert "Error: Missing command." in result.output147 140- result = runner.invoke(cli, ["obj1", "--help"])141- assert result.exit_code == 0142- assert "Show this message and exit." in result.output143-144- result = runner.invoke(cli, ["obj1", "move"])145- assert result.exit_code == 0146- assert result.output == "obj=obj1\nmove\n"147-148-148 def test_base_command(runner):149 import optparse150 151 @click.group()42 unmodified lines194 click.echo(verbose)195 196 cli.add_command(OptParseCommand("test", parser, test_callback))197 199- result = runner.invoke(200- cli, ["test", "-f", "test.txt", "-q", "whatever.txt", "whateverelse.txt"]201- )202- assert not result.exception203- assert result.output.splitlines() == [204- "whatever.txt whateverelse.txt",205- "test.txt",206- "False",207- ]198+ result = runner.invoke(cli, ["test", "-f", "f.txt", "-q", "q1.txt", "q2.txt"])199+ assert result.exception is None200+ assert result.output.splitlines() == ["q1.txt q2.txt", "f.txt", "False"]201 202 result = runner.invoke(cli, ["test", "--help"])210- assert not result.exception203+ assert result.exception is None204 assert result.output.splitlines() == [205 "Usage: foo test [OPTIONS]",206 "",207 "Options:",112 unmodified lines320 "Args: -foo|-x|--muhaha|x|y|-x",321 ]322 323 331-def test_deprecated_in_help_messages(runner):332- @click.command(deprecated=True)333- def cmd_with_help():334- """CLI HELP"""324+@pytest.mark.parametrize("doc", ["CLI HELP", None])325+def test_deprecated_in_help_messages(runner, doc):326+ @click.command(deprecated=True, help=doc)327+ def cli():328 pass329 337- result = runner.invoke(cmd_with_help, ["--help"])330+ result = runner.invoke(cli, ["--help"])331 assert "(Deprecated)" in result.output332 340- @click.command(deprecated=True)341- def cmd_without_help():342- pass333 344- result = runner.invoke(cmd_without_help, ["--help"])345- assert "(Deprecated)" in result.output346-347-334 def test_deprecated_in_invocation(runner):335 @click.command(deprecated=True)336 def deprecated_cmd():337 pass3 unmodified lines