Skip to content

Commit

Permalink
Updated tests (#90)
Browse files Browse the repository at this point in the history
* Added help param to an option in a command

* Replaced set([...]) with {...}

* Replaced set([...]) with {...}

* Actually added the help argument to the option

Sorry for the inconvenience, I've forgot to add the help argument to the option decorator, but this commit includes it

* Fixed failing flake8 test case

* Update README.md

Added hyperlink to the gh-action tests page
  • Loading branch information
GhostOps77 authored Feb 28, 2023
1 parent 1408783 commit 4bb985e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ click-repl
===

[![build](https://travis-ci.org/click-contrib/click-repl.svg?branch=master)](https://travis-ci.org/click-contrib/click-repl)
![Tests](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml/badge.svg?branch=master)
[![Tests](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/click-contrib/click-repl/actions/workflows/tests.yml)
[![License](https://img.shields.io/pypi/l/click-repl?label=License)](https://github.com/click-contrib/click-repl/LICENSE)
![Python - version](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)
![Python - version](https://img.shields.io/badge/python-3%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue)
[![PyPi - version](https://img.shields.io/badge/pypi-v0.2.0-blue)](https://pypi.org/project/click-repl/)
![wheels](https://img.shields.io/piwheels/v/click-repl?label=wheel)
![PyPI - Status](https://img.shields.io/pypi/status/click)
Expand Down
22 changes: 12 additions & 10 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ def root_command():

def test_arg_completion():
@root_command.command()
@click.argument("handler", type=click.Choice(["foo", "bar"]))
@click.argument("handler", type=click.Choice(("foo", "bar")))
def arg_cmd(handler):
pass

completions = list(c.get_completions(Document("arg-cmd ")))
assert set(x.text for x in completions) == set(["foo", "bar"])
assert set(x.text for x in completions) == {"foo", "bar"}


def test_option_completion():
@root_command.command()
@click.option("--handler", "-h", type=click.Choice(["foo", "bar"]))
@click.option(
"--handler", "-h", type=click.Choice(("foo", "bar")), help="Demo option"
)
def option_cmd(handler):
pass

completions = list(c.get_completions(Document("option-cmd ")))
assert set(x.text for x in completions) == set(["--handler", "-h"])
assert set(x.text for x in completions) == {"--handler", "-h"}

completions = list(c.get_completions(Document("option-cmd --h")))
assert set(x.text for x in completions) == set(["--handler"])
assert set(x.text for x in completions) == {"--handler"}


def test_hidden_cmd():
Expand All @@ -42,7 +44,7 @@ def hidden_cmd(handler):
pass

completions = list(c.get_completions(Document("hidden ")))
assert set(x.text for x in completions) == set(("arg-cmd", "option-cmd"))
assert set(x.text for x in completions) == {"arg-cmd", "option-cmd"}


def test_hidden_option():
Expand Down Expand Up @@ -82,9 +84,9 @@ def second_level_command_two():
c = ClickCompleter(root_group)

completions = list(c.get_completions(Document("first-level-command ")))
assert set(x.text for x in completions) == set(
["second-level-command-one", "second-level-command-two"]
)
assert set(x.text for x in completions) == {
"second-level-command-one", "second-level-command-two"
}

completions = list(c.get_completions(Document(" ")))
assert set(x.text for x in completions) == set(["first-level-command"])
assert set(x.text for x in completions) == {"first-level-command"}
8 changes: 4 additions & 4 deletions tests/test_command_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def foobar_group():
def foobar_cmd():
pass

c = ClickCompleter(click.CommandCollection(sources=[foo_group, foobar_group]))
c = ClickCompleter(click.CommandCollection(sources=(foo_group, foobar_group)))
completions = list(c.get_completions(Document("foo")))

assert set(x.text for x in completions) == set(["foo-cmd", "foobar-cmd"])
assert set(x.text for x in completions) == {"foo-cmd", "foobar-cmd"}


def test_subcommand_invocation():
Expand All @@ -43,7 +43,7 @@ def c1(user):
c = ClickCompleter(cli)

completions = list(c.get_completions(Document(" ")))
assert set(x.text for x in completions) == set(["--user", "c1"])
assert set(x.text for x in completions) == {"--user", "c1"}

completions = list(c.get_completions(Document("c1 ")))
assert set(x.text for x in completions) == set(["--user"])
assert set(x.text for x in completions) == {"--user"}
16 changes: 8 additions & 8 deletions tests/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def autocompletion_arg_cmd(handler):
pass

completions = list(c.get_completions(Document("autocompletion-cmd ")))
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


def test_shell_complete_option_v8_class_type():
Expand All @@ -61,7 +61,7 @@ def autocompletion_opt_cmd(handler):
pass

completions = list(c.get_completions(Document("autocompletion-opt-cmd ")))
assert set(x.text for x in completions) == set(("--handler", "bar"))
assert set(x.text for x in completions) == {"--handler", "bar"}


def test_shell_complete_arg_v8_func_type():
Expand All @@ -84,7 +84,7 @@ def autocompletion_cmd2(handler):
pass

completions = list(c.get_completions(Document("autocompletion-cmd2 ")))
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


def test_shell_complete_option_v8_func_type():
Expand All @@ -105,7 +105,7 @@ def autocompletion_opt_cmd(handler):
completions = list(
c.get_completions(Document("autocompletion-opt-cmd --handler "))
)
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


@pytest.mark.skipif(
Expand All @@ -122,7 +122,7 @@ def autocompletion_arg_cmd2(handler):
pass

completions = list(c.get_completions(Document("autocompletion-arg-cmd2 ")))
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


@pytest.mark.skipif(
Expand All @@ -141,7 +141,7 @@ def autocompletion_opt_cmd2(handler):
completions = list(
c.get_completions(Document("autocompletion-opt-cmd2 --handler "))
)
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


def test_arg_choices():
Expand All @@ -151,7 +151,7 @@ def arg_choices(handler):
pass

completions = list(c.get_completions(Document("arg-choices ")))
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


def test_option_choices():
Expand All @@ -161,7 +161,7 @@ def option_choices(handler):
pass

completions = list(c.get_completions(Document("option-choices --handler ")))
assert set(x.text for x in completions) == set(("foo", "bar"))
assert set(x.text for x in completions) == {"foo", "bar"}


def test_hidden_command_completions():
Expand Down

0 comments on commit 4bb985e

Please sign in to comment.