-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unhandled exception during autocomplete fix (#109)
* Unhandled exception during autocomplete fix * fix for click 7, var rename * returned coverage for pytest * added one more space before comment --------- Co-authored-by: Ondrej Pirko <ondrej.pirko@ui.com>
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/test_completion/test_common_tests/test_cmd_completion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import click | ||
from unittest import TestCase | ||
from prompt_toolkit.document import Document | ||
from click_repl import ClickCompleter | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
pass | ||
|
||
|
||
@cli.group() | ||
def cmd(): | ||
pass | ||
|
||
|
||
@cmd.command() | ||
def subcmd(): | ||
pass | ||
|
||
|
||
class Test_Command_Autocompletion(TestCase): | ||
def setUp(self): | ||
self.c = ClickCompleter(cli, click.Context(cli)) | ||
|
||
def test_valid_subcmd(self): | ||
res = list(self.c.get_completions(Document("cmd s"))) | ||
self.assertListEqual([i.text for i in res], ["subcmd"]) | ||
|
||
def test_not_valid_subcmd(self): | ||
try: | ||
res = list(self.c.get_completions(Document("not cmd"))) | ||
except Exception as e: | ||
self.fail(f"Autocompletion raised exception: {e}") | ||
self.assertListEqual(res, []) |