Skip to content
Myr

parametrize some command tests

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

authored by Israel Teneda · committed by David Lord · parent 6ef3340 · 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

1 file+24 added−38 removed

modified:tests/test_commands.py+24 added-38 removed
1import re23import pytest45import click678def test_other_command_invoke(runner):
111 unmodified lines
120 assert not result.exception121 assert result.output == "changed\n"122123124@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)122def test_group_with_args(runner):133def 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 line
139 @cli.command()140 def move():141 click.echo("move")142132 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.output146136 result = runner.invoke(cli, ["obj1"])137 assert result.exit_code == 2138 assert "Error: Missing command." in result.output147140 result = runner.invoke(cli, ["obj1", "--help"])141 assert result.exit_code == 0142 assert "Show this message and exit." in result.output143144 result = runner.invoke(cli, ["obj1", "move"])145 assert result.exit_code == 0146 assert result.output == "obj=obj1\nmove\n"147148148def test_base_command(runner):149 import optparse150151 @click.group()
42 unmodified lines
194 click.echo(verbose)195196 cli.add_command(OptParseCommand("test", parser, test_callback))197199 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"]201202 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 lines
320 "Args: -foo|-x|--muhaha|x|y|-x",321 ]322323331def 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])325def test_deprecated_in_help_messages(runner, doc):326 @click.command(deprecated=True, help=doc)327 def cli():328 pass329337 result = runner.invoke(cmd_with_help, ["--help"])330 result = runner.invoke(cli, ["--help"])331 assert "(Deprecated)" in result.output332340 @click.command(deprecated=True)341 def cmd_without_help():342 pass333344 result = runner.invoke(cmd_without_help, ["--help"])345 assert "(Deprecated)" in result.output346347334def test_deprecated_in_invocation(runner):335 @click.command(deprecated=True)336 def deprecated_cmd():337 pass
3 unmodified lines