Skip to content
Myr

test_command_decorators.py

This file

Path

tests/test_command_decorators.py

92 lines · 1.8 KiB · Python

Last changed by

remove suffixes from generated command name (#2604)David Lordbefore adoption9c5e989

History of this file

Take it

remove suffixes from generated command name (#2604)David Lordbefore adoption9c5e989

lines 1–2why, one step back
1import pytest
2

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

lines 3–15why, one step back
3import click
456def test_command_no_parens(runner):7 @click.command8 def cli():9 click.echo("hello")1011 result = runner.invoke(cli)12 assert result.exception is None13 assert result.output == "hello\n"1415

Merge branch '8.1.x'David Lordbefore adoptiond9af5cf

lines 16–35why, one step back
16def test_custom_command_no_parens(runner):
17 class CustomCommand(click.Command):18 pass1920 class CustomGroup(click.Group):21 command_class = CustomCommand2223 @click.group(cls=CustomGroup)24 def grp():25 pass2627 @grp.command28 def cli():29 click.echo("hello custom command class")3031 result = runner.invoke(cli)32 assert result.exception is None33 assert result.output == "hello custom command class\n"3435

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

lines 36–59why, one step back
36def test_group_no_parens(runner):
37 @click.group38 def grp():39 click.echo("grp1")4041 @grp.command42 def cmd1():43 click.echo("cmd1")4445 @grp.group46 def grp2():47 click.echo("grp2")4849 @grp2.command50 def cmd2():51 click.echo("cmd2")5253 result = runner.invoke(grp, ["cmd1"])54 assert result.exception is None55 assert result.output == "grp1\ncmd1\n"5657 result = runner.invoke(grp, ["grp2", "cmd2"])58 assert result.exception is None59 assert result.output == "grp1\ngrp2\ncmd2\n"

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

lines 60–73why, one step back
60
6162def test_params_argument(runner):63 opt = click.Argument(["a"])6465 @click.command(params=[opt])66 @click.argument("b")67 def cli(a, b):68 click.echo(f"{a} {b}")6970 assert cli.params[0].name == "a"71 assert cli.params[1].name == "b"72 result = runner.invoke(cli, ["1", "2"])73 assert result.output == "1 2\n"

remove suffixes from generated command name (#2604)David Lordbefore adoption9c5e989

lines 74–92why, one step back
74
7576@pytest.mark.parametrize(77 "name",78 [79 "init_data",80 "init_data_command",81 "init_data_cmd",82 "init_data_group",83 "init_data_grp",84 ],85)86def test_generate_name(name: str) -> None:87 def f():88 pass8990 f.__name__ = name91 f = click.command(f)92 assert f.name == "init-data"