def test_default_if_no_args(): cli = DefaultGroup() @cli.command() @click.argument('foo', required=False) @click.option('--bar') def foobar(foo, bar): click.echo(foo) click.echo(bar) cli.set_default_command(foobar) assert r.invoke(cli, []).output.startswith('Usage:') assert r.invoke(cli, ['foo']).output == 'foo\n\n' assert r.invoke(cli, ['foo', '--bar', 'bar']).output == 'foo\nbar\n' cli.default_if_no_args = True assert r.invoke(cli, []).output == '\n\n'
def test_deprecation(): # @cli.command(default=True) has been deprecated since 1.2. cli = DefaultGroup() pytest.deprecated_call(cli.command, default=True)
def test_set_ignore_unknown_options_to_false(): with pytest.raises(ValueError): DefaultGroup(ignore_unknown_options=False)