test_command_decorators.py
This file
Path
tests/test_command_decorators.py
71 lines · 1.5 KiB · Python
Last changed by
Merge branch '8.1.x'David Lordbefore adoptiond9af5cf
History of this fileTake it
1import click234def test_command_no_parens(runner):5 @click.command6 def cli():7 click.echo("hello")89 result = runner.invoke(cli)10 assert result.exception is None11 assert result.output == "hello\n"121314def test_custom_command_no_parens(runner):15 class CustomCommand(click.Command):16 pass1718 class CustomGroup(click.Group):19 command_class = CustomCommand2021 @click.group(cls=CustomGroup)22 def grp():23 pass2425 @grp.command26 def cli():27 click.echo("hello custom command class")2829 result = runner.invoke(cli)30 assert result.exception is None31 assert result.output == "hello custom command class\n"323334def test_group_no_parens(runner):35 @click.group36 def grp():37 click.echo("grp1")3839 @grp.command40 def cmd1():41 click.echo("cmd1")4243 @grp.group44 def grp2():45 click.echo("grp2")4647 @grp2.command48 def cmd2():49 click.echo("cmd2")5051 result = runner.invoke(grp, ["cmd1"])52 assert result.exception is None53 assert result.output == "grp1\ncmd1\n"5455 result = runner.invoke(grp, ["grp2", "cmd2"])56 assert result.exception is None57 assert result.output == "grp1\ngrp2\ncmd2\n"585960def test_params_argument(runner):61 opt = click.Argument(["a"])6263 @click.command(params=[opt])64 @click.argument("b")65 def cli(a, b):66 click.echo(f"{a} {b}")6768 assert cli.params[0].name == "a"69 assert cli.params[1].name == "b"70 result = runner.invoke(cli, ["1", "2"])71 assert result.output == "1 2\n"