Skip to content
Myr

test_arguments.py

This file

Path

tests/test_arguments.py

49 lines · 1.2 KiB · Python

Last changed by

Added support for nargs in other placesArmin Ronacherbefore adoption2e8354a

History of this file

Take it

1# -*- coding: utf-8 -*-2import click345def test_nargs_star(runner):6    @click.command()7    @click.argument('src', nargs=-1)8    @click.argument('dst')9    def copy(src, dst):10        click.echo('src=%s' % '|'.join(src))11        click.echo('dst=%s' % dst)1213    result = runner.invoke(copy, ['foo.txt', 'bar.txt', 'dir'])14    assert not result.exception15    assert result.output.splitlines() == [16        'src=foo.txt|bar.txt',17        'dst=dir',18    ]192021def test_nargs_tup(runner):22    @click.command()23    @click.argument('name', nargs=1)24    @click.argument('point', nargs=2, type=click.INT)25    def copy(name, point):26        click.echo('name=%s' % name)27        click.echo('point=%d/%d' % point)2829    result = runner.invoke(copy, ['peter', '1', '2'])30    assert not result.exception31    assert result.output.splitlines() == [32        'name=peter',33        'point=1/2',34    ]353637def test_nargs_err(runner):38    @click.command()39    @click.argument('x')40    def copy(x):41        click.echo(x)4243    result = runner.invoke(copy, ['foo'])44    assert not result.exception45    assert result.output == 'foo\n'4647    result = runner.invoke(copy, ['foo', 'bar'])48    assert result.exit_code == 249    assert 'Got unexpected extra argument (bar)' in result.output