Skip to content
Myr

test_options.py

This file

Path

tests/test_options.py

51 lines · 1.5 KiB · Python

Last changed by

Added support for requiring with multiples.Armin Ronacherbefore adoptionfe89108

History of this file

Take it

Added support for alternative prefix charsArmin Ronacherbefore adoption38b3b41

lines 1–19why, one step back
1# -*- coding: utf-8 -*-
2import re3import click456def test_prefixes(runner):7 @click.command()8 @click.option('++foo', is_flag=True, help='das foo')9 @click.option('--bar', is_flag=True, help='das bar')10 def cli(foo, bar):11 click.echo('foo=%s bar=%s' % (foo, bar))1213 result = runner.invoke(cli, ['++foo', '--bar'])14 assert not result.exception15 assert result.output == 'foo=True bar=True\n'1617 result = runner.invoke(cli, ['--help'])18 assert re.search(r'\+\+foo\s+das foo', result.output) is not None19 assert re.search(r'--bar\s+das bar', result.output) is not None

Added count support and int rangesArmin Ronacherbefore adoption81930b5

lines 20–36why, one step back
20
2122def test_counting(runner):23 @click.command()24 @click.option('-v', count=True, help='Verbosity',25 type=click.IntRange(0, 3))26 def cli(v):27 click.echo('verbosity=%d' % v)2829 result = runner.invoke(cli, ['-vvv'])30 assert not result.exception31 assert result.output == 'verbosity=3\n'3233 result = runner.invoke(cli, ['-vvvv'])34 assert result.exception35 assert 'Invalid value for "-v": 4 is not in the valid range of 0 to 3.' \36 in result.output

Added support for requiring with multiples.Armin Ronacherbefore adoptionfe89108

lines 37–51why, one step back
37
3839def test_multiple_required(runner):40 @click.command()41 @click.option('-m', '--message', multiple=True, required=True)42 def cli(message):43 click.echo('\n'.join(message))4445 result = runner.invoke(cli, ['-m', 'foo', '-mbar'])46 assert not result.exception47 assert result.output == 'foo\nbar\n'4849 result = runner.invoke(cli, [])50 assert result.exception51 assert 'Error: Missing option "-m" / "--message".' in result.output