Skip to content
Myr

test_commands.py

This file

Path

tests/test_commands.py

58 lines · 1.3 KiB · Python

Last changed by

Added support for default overrides. This fixes #42Armin Ronacherbefore adoptione77783d

History of this file

Take it

1# -*- coding: utf-8 -*-2import re3import click456def test_other_command_invoke(runner):7    @click.command()8    @click.pass_context9    def cli(ctx):10        return ctx.invoke(other_cmd, 42)1112    @click.command()13    @click.argument('arg', type=click.INT)14    def other_cmd(arg):15        click.echo(arg)1617    result = runner.invoke(cli, [])18    assert not result.exception19    assert result.output == '42\n'202122def test_auto_shorthelp(runner):23    @click.group()24    def cli():25        pass2627    @cli.command()28    def short():29        """This is a short text."""3031    @cli.command()32    def long():33        """This is a long text that is too long to show as short help34        and will be truncated instead."""3536    result = runner.invoke(cli, ['--help'])37    assert re.search(38        r'Commands:\n\s+'39        r'long\s+This is a long text that is too long to show\.\.\.\n\s+'40        r'short\s+This is a short text\.', result.output) is not None414243def test_default_maps(runner):44    @click.group()45    def cli():46        pass4748    @cli.command()49    @click.option('--name', default='normal')50    def foo(name):51        click.echo(name)5253    result = runner.invoke(cli, ['foo'], default_map={54        'foo': {'name': 'changed'}55    })5657    assert not result.exception58    assert result.output == 'changed\n'