# -*- coding: utf-8 -*- import re import click def test_prefixes(runner): @click.command() @click.option('++foo', is_flag=True, help='das foo') @click.option('--bar', is_flag=True, help='das bar') def cli(foo, bar): click.echo('foo=%s bar=%s' % (foo, bar)) result = runner.invoke(cli, ['++foo', '--bar']) assert not result.exception assert result.output == 'foo=True bar=True\n' result = runner.invoke(cli, ['--help']) assert re.search(r'\+\+foo\s+das foo', result.output) is not None assert re.search(r'--bar\s+das bar', result.output) is not None def test_counting(runner): @click.command() @click.option('-v', count=True, help='Verbosity', type=click.IntRange(0, 3)) def cli(v): click.echo('verbosity=%d' % v) result = runner.invoke(cli, ['-vvv']) assert not result.exception assert result.output == 'verbosity=3\n' result = runner.invoke(cli, ['-vvvv']) assert result.exception assert 'Invalid value for "-v": 4 is not in the valid range of 0 to 3.' \ in result.output def test_multiple_required(runner): @click.command() @click.option('-m', '--message', multiple=True, required=True) def cli(message): click.echo('\n'.join(message)) result = runner.invoke(cli, ['-m', 'foo', '-mbar']) assert not result.exception assert result.output == 'foo\nbar\n' result = runner.invoke(cli, []) assert result.exception assert 'Error: Missing option "-m" / "--message".' in result.output