Skip to content
Myr

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 file

Take it

Merge pull request #1896 from angus-lherrou/1359-uncalled-decoratorsDavid Lordbefore adoption24992ce

lines 1–13why, one step back
1import click
234def 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"1213

Merge branch '8.1.x'David Lordbefore adoptiond9af5cf

lines 14–33why, one step back
14def 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"3233

Merge pull request #1896 from angus-lherrou/1359-uncalled-decoratorsDavid Lordbefore adoption24992ce

lines 34–57why, one step back
34def 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"

Merge pull request #2203 from pallets/command-decorator-paramsDavid Lordbefore adoption55b2715

lines 58–71why, one step back
58
5960def 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"