fork/mons

git clone https://git.julia.blue/fork/mons

coloursofnoiseAdd tests to cover config and extended help sections384a235

main
1.4 KiB41 linesraw
1import warnings
2
3import click
4
5
6def test_command_help(command: "click.Command"):
7    if command.hidden:
8        return
9
10    assert command.help, f"Command '{command.name}' is missing help text"
11    assert (
12        command.get_short_help_str()
13    ), f"Command '{command.name}' is missing short help text"
14
15
16def test_option_help(command: "click.Command"):
17    if command.hidden:
18        return
19
20    for param in command.params:
21        if isinstance(param, click.Option) and not param.hidden:
22            assert (
23                param.help
24            ), f"Option '{param.name}' for command '{command.name}' is missing help text"
25            assert param.help.strip().endswith(
26                "."
27            ), f"The help text for option '{param.name}' for command '{command.name}' does not end with a '.'"
28
29
30def test_no_args_is_help(command: "click.Command"):
31    if command.hidden:
32        return
33    # Note: commands with only a clickExt.OptionalArg required do *not* fail this test.
34    # When an optional arg is applied 'no_args_is_help' is disabled.
35
36    if command.no_args_is_help:
37        assert any(
38            param.required for param in command.params
39        ), "Command can be invoked with no arguments, but has 'no_args_is_help' enabled."
40    elif any(param.required for param in command.params):
41        warnings.warn("Command does not have 'no_args_is_help' enabled, but could.")