From c8d3300a2467d3a017aac1d24a92cb254ce921fe Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 11 Aug 2014 11:26:46 +0200 Subject: Added support for multiple defaults on options and nargs --- tests/test_defaults.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/test_defaults.py (limited to 'tests/test_defaults.py') diff --git a/tests/test_defaults.py b/tests/test_defaults.py new file mode 100644 index 0000000..dba5a9c --- /dev/null +++ b/tests/test_defaults.py @@ -0,0 +1,46 @@ +import click + + +def test_basic_defaults(runner): + @click.command() + @click.option('--foo', default=42, type=click.FLOAT) + def cli(foo): + assert type(foo) is float + click.echo('FOO:[%s]' % foo) + + result = runner.invoke(cli, []) + assert not result.exception + assert 'FOO:[42.0]' in result.output + + +def test_multiple_defaults(runner): + @click.command() + @click.option('--foo', default=[23, 42], type=click.FLOAT, + multiple=True) + def cli(foo): + for item in foo: + assert type(item) is float + click.echo(item) + + result = runner.invoke(cli, []) + assert not result.exception + assert result.output.splitlines() == [ + '23.0', + '42.0', + ] + + +def test_nargs_plus_multiple(runner): + @click.command() + @click.option('--arg', default=((1, 2), (3, 4)), + nargs=2, multiple=True, type=click.INT) + def cli(arg): + for item in arg: + click.echo('<%d|%d>' % item) + + result = runner.invoke(cli, []) + assert not result.exception + assert result.output.splitlines() == [ + '<1|2>', + '<3|4>', + ] -- cgit v1.2.1