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

Added support for command forwarding.Armin Ronacherbefore adoption506e4e7

line 1why, one step back
1# -*- coding: utf-8 -*-

Auto truncate short help instead of hiding it. Fixes #53Armin Ronacherbefore adoptiona25bf13

line 2why, one step back
2import re

Added support for command forwarding.Armin Ronacherbefore adoption506e4e7

lines 3–19why, one step back
3import click
456def 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'

Auto truncate short help instead of hiding it. Fixes #53Armin Ronacherbefore adoptiona25bf13

lines 20–40why, one step back
20
2122def 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 None

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

lines 41–58why, one step back
41
4243def 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'