Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing documentation: testing of shell completion #2299

Open
seebi opened this issue May 28, 2022 · 1 comment
Open

missing documentation: testing of shell completion #2299

seebi opened this issue May 28, 2022 · 1 comment
Labels

Comments

@seebi
Copy link

seebi commented May 28, 2022

I currently migrate an application to click 8.x and have to migrate all the completion functions as well as the test code for shell completion.

My working code for click 7.x shell completion testing is based on @davidism answer on this post #1453 2 years ago and worked fine.

However, with click 8.x, there is no get_choices anymore and the documentation at
https://click.palletsprojects.com/en/8.1.x/testing/ does not mention shell completion testing.

Can you give me a new example or a link please?

This time I will prepare an MR for https://github.com/pallets/click/blob/8.1.x/docs/testing.rst :-)

@juhoinkinen
Copy link

I mimicked the completion tests in Click itself to make up this kind of testing for annif CLI application, basically just the following:

from click.shell_completion import ShellComplete


def _get_completions(cli, args, incomplete):
    comp = ShellComplete(cli, {}, cli.name, "_ANNIF_COMPLETE")
    return comp.get_completions(args, incomplete)


def _get_words(cli, args, incomplete):
    return [c.value for c in _get_completions(cli, args, incomplete)]


def test_completion_base_all_options():
    completions = _get_words(annif.cli.cli, [""], "--")
    assert completions == [
        "--env-file",
        "--app",
        "--debug",
        "--no-debug",
        "--version",
        "--help",
    ]

def test_completion_base_version_option():
    completions = _get_words(annif.cli.cli, [""], "--ver")
    assert completions == [
        "--version",
    ]

@davidism davidism added the docs label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants