test_command_decorators.py
This file
Path
tests/test_command_decorators.py
92 lines · 1.8 KiB · Python
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 45f89cd point at it.
Improve typing on Windows (#2803)Andreas Backxbefore adoption45f89cd
lines 1–92why, one step back1import pytest23import click456def 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"141516def 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"343536def 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"606162def 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"747576@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"