Skip to content

Commit 883d87c

Browse files
committed
Increased test coverage.
1 parent 1f49511 commit 883d87c

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

cmd2/completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
overload,
2222
)
2323

24-
if TYPE_CHECKING:
24+
if TYPE_CHECKING: # pragma: no cover
2525
from .cmd2 import Cmd
2626
from .command_definition import CommandSet
2727

cmd2/pt_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
utils,
2323
)
2424

25-
if TYPE_CHECKING:
25+
if TYPE_CHECKING: # pragma: no cover
2626
from .cmd2 import Cmd
2727

2828

tests/test_argparse_custom.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
Cmd2ArgumentParser,
1111
constants,
1212
)
13-
from cmd2.argparse_custom import generate_range_error
13+
from cmd2.argparse_custom import (
14+
ChoicesCallable,
15+
generate_range_error,
16+
)
1417

1518
from .conftest import run_cmd
1619

@@ -75,6 +78,19 @@ def test_apcustom_no_choices_callables_when_nargs_is_0(kwargs) -> None:
7578
assert 'None of the following parameters can be used on an action that takes no arguments' in str(excinfo.value)
7679

7780

81+
def test_apcustom_choices_callables_wrong_property() -> None:
82+
"""Test using the wrong property when retrieving the to_call value from a ChoicesCallable."""
83+
choices_callable = ChoicesCallable(is_completer=True, to_call=fake_func)
84+
with pytest.raises(AttributeError) as excinfo:
85+
to_call = choices_callable.choices_provider
86+
assert 'This instance is configured as a completer' in str(excinfo.value)
87+
88+
choices_callable = ChoicesCallable(is_completer=False, to_call=fake_func)
89+
with pytest.raises(AttributeError) as excinfo:
90+
to_call = choices_callable.completer
91+
assert 'This instance is configured as a choices_provider' in str(excinfo.value)
92+
93+
7894
def test_apcustom_usage() -> None:
7995
usage = "A custom usage statement"
8096
parser = Cmd2ArgumentParser(usage=usage)

tests/test_completion.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ def test_no_completer(cmd2_app) -> None:
947947
assert completions.to_strings() == Completions.from_values(expected).to_strings()
948948

949949

950-
def test_wordbreak_in_command(cmd2_app) -> None:
950+
def test_word_break_in_command(cmd2_app) -> None:
951951
text = ''
952952
line = f'"{text}'
953953
endidx = len(line)
@@ -983,6 +983,17 @@ def test_complete_multiline_on_multiple_lines(cmd2_app) -> None:
983983
assert completions.to_strings() == Completions.from_values(expected).to_strings()
984984

985985

986+
def test_completions_iteration() -> None:
987+
items = [CompletionItem(1), CompletionItem(2)]
988+
completions = Completions(items)
989+
990+
# Test __iter__
991+
assert list(completions) == items
992+
993+
# Test __reversed__
994+
assert list(reversed(completions)) == items[::-1]
995+
996+
986997
# Used by redirect_complete tests
987998
class RedirCompType(enum.Enum):
988999
SHELL_CMD = (1,)

0 commit comments

Comments
 (0)