Skip to content
Myr

test_bashcomplete.py

This file

Path

tests/test_bashcomplete.py

62 lines · 1.7 KiB · Python

Last changed by

Fix #630: Bash completion for nested commands brokenPeter Kelleybefore adoption8af7ec1

History of this file

Take it

1# -*- coding: utf-8 -*-23import click4from click._bashcomplete import get_choices567def test_single_command():8    @click.command()9    @click.option('--local-opt')10    def cli(local_opt):11        pass1213    assert list(get_choices(cli, 'lol', [], '-')) == ['--local-opt']14    assert list(get_choices(cli, 'lol', [], '')) == []151617def test_small_chain():18    @click.group()19    @click.option('--global-opt')20    def cli(global_opt):21        pass2223    @cli.command()24    @click.option('--local-opt')25    def sub(local_opt):26        pass2728    assert list(get_choices(cli, 'lol', [], '')) == ['sub']29    assert list(get_choices(cli, 'lol', [], '-')) == ['--global-opt']30    assert list(get_choices(cli, 'lol', ['sub'], '')) == []31    assert list(get_choices(cli, 'lol', ['sub'], '-')) == ['--local-opt']323334def test_long_chain():35    @click.group('cli')36    @click.option('--cli-opt')37    def cli(cli_opt):38        pass3940    @cli.group('asub')41    @click.option('--asub-opt')42    def asub(asub_opt):43        pass4445    @asub.group('bsub')46    @click.option('--bsub-opt')47    def bsub(bsub_opt):48        pass4950    @bsub.command('csub')51    @click.option('--csub-opt')52    def csub(csub_opt):53        pass5455    assert list(get_choices(cli, 'lol', [], '-')) == ['--cli-opt']56    assert list(get_choices(cli, 'lol', [], '')) == ['asub']57    assert list(get_choices(cli, 'lol', ['asub'], '-')) == ['--asub-opt']58    assert list(get_choices(cli, 'lol', ['asub'], '')) == ['bsub']59    assert list(get_choices(cli, 'lol', ['asub', 'bsub'], '-')) == ['--bsub-opt']60    assert list(get_choices(cli, 'lol', ['asub', 'bsub'], '')) == ['csub']61    assert list(get_choices(cli, 'lol', ['asub', 'bsub', 'csub'], '-')) == ['--csub-opt']62    assert list(get_choices(cli, 'lol', ['asub', 'bsub', 'csub'], '')) == []