Skip to content
Myr

test_command_decorators.py

This file

Path

tests/test_command_decorators.py

51 lines · 1.1 KiB · Python

Last changed by

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

History of this file

Take it

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

lines 1–37why, 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"121314def test_group_no_parens(runner):15 @click.group16 def grp():17 click.echo("grp1")1819 @grp.command20 def cmd1():21 click.echo("cmd1")2223 @grp.group24 def grp2():25 click.echo("grp2")2627 @grp2.command28 def cmd2():29 click.echo("cmd2")3031 result = runner.invoke(grp, ["cmd1"])32 assert result.exception is None33 assert result.output == "grp1\ncmd1\n"3435 result = runner.invoke(grp, ["grp2", "cmd2"])36 assert result.exception is None37 assert result.output == "grp1\ngrp2\ncmd2\n"

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

lines 38–51why, one step back
38
3940def test_params_argument(runner):41 opt = click.Argument(["a"])4243 @click.command(params=[opt])44 @click.argument("b")45 def cli(a, b):46 click.echo(f"{a} {b}")4748 assert cli.params[0].name == "a"49 assert cli.params[1].name == "b"50 result = runner.invoke(cli, ["1", "2"])51 assert result.output == "1 2\n"