python-click/tests/test_basic.py

567 lines
15 KiB
Python
Raw Normal View History

2014-10-16 20:40:34 +02:00
import os
import uuid
2021-10-10 03:31:57 +02:00
from itertools import chain
import pytest
2020-07-21 08:23:42 +02:00
2014-10-16 20:40:34 +02:00
import click
def test_basic_functionality(runner):
@click.command()
def cli():
"""Hello World!"""
2020-07-21 08:23:42 +02:00
click.echo("I EXECUTED")
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "Hello World!" in result.output
assert "Show this message and exit." in result.output
2014-10-16 20:40:34 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "I EXECUTED" not in result.output
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "I EXECUTED" in result.output
2014-10-16 20:40:34 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
def test_repr():
@click.command()
def command():
pass
@click.group()
def group():
pass
@group.command()
def subcommand():
pass
assert repr(command) == "<Command command>"
assert repr(group) == "<Group group>"
assert repr(subcommand) == "<Command subcommand>"
2014-10-16 20:40:34 +02:00
def test_return_values():
@click.command()
def cli():
return 42
2020-07-21 08:23:42 +02:00
with cli.make_context("foo", []) as ctx:
2014-10-16 20:40:34 +02:00
rv = cli.invoke(ctx)
2020-07-21 08:23:42 +02:00
assert rv == 42
2014-10-16 20:40:34 +02:00
def test_basic_group(runner):
@click.group()
def cli():
"""This is the root."""
2020-07-21 08:23:42 +02:00
click.echo("ROOT EXECUTED")
2014-10-16 20:40:34 +02:00
@cli.command()
def subcommand():
"""This is a subcommand."""
2020-07-21 08:23:42 +02:00
click.echo("SUBCOMMAND EXECUTED")
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "COMMAND [ARGS]..." in result.output
assert "This is the root" in result.output
assert "This is a subcommand." in result.output
2014-10-16 20:40:34 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "ROOT EXECUTED" not in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["subcommand"])
2014-10-16 20:40:34 +02:00
assert not result.exception
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "ROOT EXECUTED" in result.output
assert "SUBCOMMAND EXECUTED" in result.output
2014-10-16 20:40:34 +02:00
2021-10-10 03:31:57 +02:00
def test_group_commands_dict(runner):
"""A Group can be built with a dict of commands."""
@click.command()
def sub():
click.echo("sub", nl=False)
cli = click.Group(commands={"other": sub})
result = runner.invoke(cli, ["other"])
assert result.output == "sub"
def test_group_from_list(runner):
"""A Group can be built with a list of commands."""
@click.command()
def sub():
click.echo("sub", nl=False)
cli = click.Group(commands=[sub])
result = runner.invoke(cli, ["sub"])
assert result.output == "sub"
2014-10-16 20:40:34 +02:00
def test_basic_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--foo", default="no value")
2014-10-16 20:40:34 +02:00
def cli(foo):
2021-10-10 03:31:57 +02:00
click.echo(f"FOO:[{foo}]")
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[no value]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo=42"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[42]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo"])
2014-10-16 20:40:34 +02:00
assert result.exception
2021-10-10 03:31:57 +02:00
assert "Option '--foo' requires an argument." in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo="])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[]" in result.output
2014-10-16 20:40:34 +02:00
2021-10-10 03:31:57 +02:00
result = runner.invoke(cli, ["--foo=\N{SNOWMAN}"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2021-10-10 03:31:57 +02:00
assert "FOO:[\N{SNOWMAN}]" in result.output
2014-10-16 20:40:34 +02:00
def test_int_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--foo", default=42)
2014-10-16 20:40:34 +02:00
def cli(foo):
2021-10-10 03:31:57 +02:00
click.echo(f"FOO:[{foo * 2}]")
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[84]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo=23"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[46]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo=bar"])
2014-10-16 20:40:34 +02:00
assert result.exception
2021-10-10 03:31:57 +02:00
assert "Invalid value for '--foo': 'bar' is not a valid integer." in result.output
2014-10-16 20:40:34 +02:00
def test_uuid_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option(
"--u", default="ba122011-349f-423b-873b-9d6a79c688ab", type=click.UUID
)
2014-10-16 20:40:34 +02:00
def cli(u):
assert type(u) is uuid.UUID
2021-10-10 03:31:57 +02:00
click.echo(f"U:[{u}]")
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "U:[ba122011-349f-423b-873b-9d6a79c688ab]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--u=821592c1-c50e-4971-9cd6-e89dc6832f86"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "U:[821592c1-c50e-4971-9cd6-e89dc6832f86]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--u=bar"])
2014-10-16 20:40:34 +02:00
assert result.exception
2021-10-10 03:31:57 +02:00
assert "Invalid value for '--u': 'bar' is not a valid UUID." in result.output
2014-10-16 20:40:34 +02:00
def test_float_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--foo", default=42, type=click.FLOAT)
2014-10-16 20:40:34 +02:00
def cli(foo):
assert type(foo) is float
2021-10-10 03:31:57 +02:00
click.echo(f"FOO:[{foo}]")
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[42.0]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo=23.5"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert "FOO:[23.5]" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--foo=bar"])
2014-10-16 20:40:34 +02:00
assert result.exception
2021-10-10 03:31:57 +02:00
assert "Invalid value for '--foo': 'bar' is not a valid float." in result.output
2014-10-16 20:40:34 +02:00
def test_boolean_option(runner):
for default in True, False:
2020-07-21 08:23:42 +02:00
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--with-foo/--without-foo", default=default)
2014-10-16 20:40:34 +02:00
def cli(with_foo):
click.echo(with_foo)
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--with-foo"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "True\n"
result = runner.invoke(cli, ["--without-foo"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "False\n"
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2021-10-10 03:31:57 +02:00
assert result.output == f"{default}\n"
2014-10-16 20:40:34 +02:00
for default in True, False:
2020-07-21 08:23:42 +02:00
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--flag", is_flag=True, default=default)
2014-10-16 20:40:34 +02:00
def cli(flag):
click.echo(flag)
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--flag"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2021-10-10 03:31:57 +02:00
assert result.output == f"{not default}\n"
2014-10-16 20:40:34 +02:00
result = runner.invoke(cli, [])
assert not result.exception
2021-10-10 03:31:57 +02:00
assert result.output == f"{default}\n"
2014-10-16 20:40:34 +02:00
2021-10-10 03:31:57 +02:00
@pytest.mark.parametrize(
("value", "expect"),
chain(
((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),
((x, "False") for x in ("0", "false", "f", "no", "n", "off")),
),
)
def test_boolean_conversion(runner, value, expect):
@click.command()
@click.option("--flag", type=bool)
def cli(flag):
click.echo(flag, nl=False)
2018-09-06 20:55:10 +02:00
2021-10-10 03:31:57 +02:00
result = runner.invoke(cli, ["--flag", value])
assert result.output == expect
2018-09-06 20:55:10 +02:00
2021-10-10 03:31:57 +02:00
result = runner.invoke(cli, ["--flag", value.title()])
assert result.output == expect
2018-09-06 20:55:10 +02:00
2014-10-16 20:40:34 +02:00
def test_file_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--file", type=click.File("w"))
2014-10-16 20:40:34 +02:00
def input(file):
2020-07-21 08:23:42 +02:00
file.write("Hello World!\n")
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--file", type=click.File("r"))
2014-10-16 20:40:34 +02:00
def output(file):
click.echo(file.read())
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
result_in = runner.invoke(input, ["--file=example.txt"])
result_out = runner.invoke(output, ["--file=example.txt"])
2014-10-16 20:40:34 +02:00
assert not result_in.exception
2020-07-21 08:23:42 +02:00
assert result_in.output == ""
2014-10-16 20:40:34 +02:00
assert not result_out.exception
2020-07-21 08:23:42 +02:00
assert result_out.output == "Hello World!\n\n"
2014-10-16 20:40:34 +02:00
def test_file_lazy_mode(runner):
do_io = False
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--file", type=click.File("w"))
2014-10-16 20:40:34 +02:00
def input(file):
if do_io:
2020-07-21 08:23:42 +02:00
file.write("Hello World!\n")
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--file", type=click.File("r"))
2014-10-16 20:40:34 +02:00
def output(file):
pass
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
os.mkdir("example.txt")
2014-10-16 20:40:34 +02:00
do_io = True
2020-07-21 08:23:42 +02:00
result_in = runner.invoke(input, ["--file=example.txt"])
2014-10-16 20:40:34 +02:00
assert result_in.exit_code == 1
do_io = False
2020-07-21 08:23:42 +02:00
result_in = runner.invoke(input, ["--file=example.txt"])
2014-10-16 20:40:34 +02:00
assert result_in.exit_code == 0
2020-07-21 08:23:42 +02:00
result_out = runner.invoke(output, ["--file=example.txt"])
2014-10-16 20:40:34 +02:00
assert result_out.exception
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--file", type=click.File("w", lazy=False))
2014-10-16 20:40:34 +02:00
def input_non_lazy(file):
2020-07-21 08:23:42 +02:00
file.write("Hello World!\n")
2014-10-16 20:40:34 +02:00
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
os.mkdir("example.txt")
result_in = runner.invoke(input_non_lazy, ["--file=example.txt"])
2014-10-16 20:40:34 +02:00
assert result_in.exit_code == 2
2021-10-10 03:31:57 +02:00
assert "Invalid value for '--file': 'example.txt'" in result_in.output
2014-10-16 20:40:34 +02:00
def test_path_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("-O", type=click.Path(file_okay=False, exists=True, writable=True))
2014-10-16 20:40:34 +02:00
def write_to_dir(o):
2020-07-21 08:23:42 +02:00
with open(os.path.join(o, "foo.txt"), "wb") as f:
f.write(b"meh\n")
2014-10-16 20:40:34 +02:00
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
os.mkdir("test")
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(write_to_dir, ["-O", "test"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
with open("test/foo.txt", "rb") as f:
assert f.read() == b"meh\n"
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(write_to_dir, ["-O", "test/foo.txt"])
assert "is a file" in result.output
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("-f", type=click.Path(exists=True))
2014-10-16 20:40:34 +02:00
def showtype(f):
2021-10-10 03:31:57 +02:00
click.echo(f"is_file={os.path.isfile(f)}")
click.echo(f"is_dir={os.path.isdir(f)}")
2014-10-16 20:40:34 +02:00
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
result = runner.invoke(showtype, ["-f", "xxx"])
assert "does not exist" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(showtype, ["-f", "."])
assert "is_file=False" in result.output
assert "is_dir=True" in result.output
2014-10-16 20:40:34 +02:00
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("-f", type=click.Path())
2014-10-16 20:40:34 +02:00
def exists(f):
2021-10-10 03:31:57 +02:00
click.echo(f"exists={os.path.exists(f)}")
2014-10-16 20:40:34 +02:00
with runner.isolated_filesystem():
2020-07-21 08:23:42 +02:00
result = runner.invoke(exists, ["-f", "xxx"])
assert "exists=False" in result.output
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(exists, ["-f", "."])
assert "exists=True" in result.output
2014-10-16 20:40:34 +02:00
def test_choice_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--method", type=click.Choice(["foo", "bar", "baz"]))
2014-10-16 20:40:34 +02:00
def cli(method):
click.echo(method)
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--method=foo"])
2014-10-16 20:40:34 +02:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "foo\n"
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--method=meh"])
2014-10-16 20:40:34 +02:00
assert result.exit_code == 2
2020-07-21 08:23:42 +02:00
assert (
2021-10-10 03:31:57 +02:00
"Invalid value for '--method': 'meh' is not one of 'foo', 'bar', 'baz'."
in result.output
2020-07-21 08:23:42 +02:00
)
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
assert "--method [foo|bar|baz]" in result.output
2014-10-16 20:40:34 +02:00
2021-10-10 03:31:57 +02:00
def test_choice_argument(runner):
@click.command()
@click.argument("method", type=click.Choice(["foo", "bar", "baz"]))
def cli(method):
click.echo(method)
result = runner.invoke(cli, ["foo"])
assert not result.exception
assert result.output == "foo\n"
result = runner.invoke(cli, ["meh"])
assert result.exit_code == 2
assert (
"Invalid value for '{foo|bar|baz}': 'meh' is not one of 'foo',"
" 'bar', 'baz'." in result.output
)
result = runner.invoke(cli, ["--help"])
assert "{foo|bar|baz}" in result.output
2019-01-07 17:51:19 +01:00
def test_datetime_option_default(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--start_date", type=click.DateTime())
2019-01-07 17:51:19 +01:00
def cli(start_date):
2020-07-21 08:23:42 +02:00
click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))
2019-01-07 17:51:19 +01:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--start_date=2015-09-29"])
2019-01-07 17:51:19 +01:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "2015-09-29T00:00:00\n"
2019-01-07 17:51:19 +01:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--start_date=2015-09-29T09:11:22"])
2019-01-07 17:51:19 +01:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "2015-09-29T09:11:22\n"
2019-01-07 17:51:19 +01:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--start_date=2015-09"])
2019-01-07 17:51:19 +01:00
assert result.exit_code == 2
2020-07-21 08:23:42 +02:00
assert (
2021-10-10 03:31:57 +02:00
"Invalid value for '--start_date': '2015-09' does not match the formats"
" '%Y-%m-%d', '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d %H:%M:%S'."
2020-07-21 08:23:42 +02:00
) in result.output
2019-01-07 17:51:19 +01:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
assert (
"--start_date [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]" in result.output
)
2019-01-07 17:51:19 +01:00
def test_datetime_option_custom(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--start_date", type=click.DateTime(formats=["%A %B %d, %Y"]))
2019-01-07 17:51:19 +01:00
def cli(start_date):
2020-07-21 08:23:42 +02:00
click.echo(start_date.strftime("%Y-%m-%dT%H:%M:%S"))
2019-01-07 17:51:19 +01:00
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--start_date=Wednesday June 05, 2010"])
2019-01-07 17:51:19 +01:00
assert not result.exception
2020-07-21 08:23:42 +02:00
assert result.output == "2010-06-05T00:00:00\n"
2019-01-07 17:51:19 +01:00
2014-10-16 20:40:34 +02:00
def test_required_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--foo", required=True)
2014-10-16 20:40:34 +02:00
def cli(foo):
click.echo(foo)
result = runner.invoke(cli, [])
assert result.exit_code == 2
2020-07-21 08:23:42 +02:00
assert "Missing option '--foo'" in result.output
2014-10-16 20:40:34 +02:00
def test_evaluation_order(runner):
called = []
2018-09-06 20:55:10 +02:00
def memo(ctx, param, value):
2014-10-16 20:40:34 +02:00
called.append(value)
return value
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--missing", default="missing", is_eager=False, callback=memo)
@click.option("--eager-flag1", flag_value="eager1", is_eager=True, callback=memo)
@click.option("--eager-flag2", flag_value="eager2", is_eager=True, callback=memo)
@click.option("--eager-flag3", flag_value="eager3", is_eager=True, callback=memo)
@click.option("--normal-flag1", flag_value="normal1", is_eager=False, callback=memo)
@click.option("--normal-flag2", flag_value="normal2", is_eager=False, callback=memo)
@click.option("--normal-flag3", flag_value="normal3", is_eager=False, callback=memo)
2014-10-16 20:40:34 +02:00
def cli(**x):
pass
2020-07-21 08:23:42 +02:00
result = runner.invoke(
cli,
[
"--eager-flag2",
"--eager-flag1",
"--normal-flag2",
"--eager-flag3",
"--normal-flag3",
"--normal-flag3",
"--normal-flag1",
"--normal-flag1",
],
)
2014-10-16 20:40:34 +02:00
assert not result.exception
assert called == [
2020-07-21 08:23:42 +02:00
"eager2",
"eager1",
"eager3",
"normal2",
"normal3",
"normal1",
"missing",
2014-10-16 20:40:34 +02:00
]
2018-09-06 20:55:10 +02:00
def test_hidden_option(runner):
@click.command()
2020-07-21 08:23:42 +02:00
@click.option("--nope", hidden=True)
2018-09-06 20:55:10 +02:00
def cli(nope):
click.echo(nope)
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
2018-09-06 20:55:10 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "--nope" not in result.output
2018-09-06 20:55:10 +02:00
def test_hidden_command(runner):
@click.group()
def cli():
pass
@cli.command(hidden=True)
def nope():
pass
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
2018-09-06 20:55:10 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "nope" not in result.output
2018-09-06 20:55:10 +02:00
def test_hidden_group(runner):
@click.group()
def cli():
pass
@cli.group(hidden=True)
def subgroup():
pass
@subgroup.command()
def nope():
pass
2020-07-21 08:23:42 +02:00
result = runner.invoke(cli, ["--help"])
2018-09-06 20:55:10 +02:00
assert result.exit_code == 0
2020-07-21 08:23:42 +02:00
assert "subgroup" not in result.output
assert "nope" not in result.output
2021-10-10 03:31:57 +02:00
def test_summary_line(runner):
@click.group()
def cli():
pass
@cli.command()
def cmd():
"""
Summary line without period
Here is a sentence. And here too.
"""
pass
result = runner.invoke(cli, ["--help"])
assert "Summary line without period" in result.output
assert "Here is a sentence." not in result.output
def test_help_invalid_default(runner):
cli = click.Command(
"cli",
params=[
click.Option(
["-a"],
type=click.Path(exists=True),
default="not found",
show_default=True,
),
],
)
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "default: not found" in result.output