File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed
Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 2222 utils ,
2323)
2424
25- if TYPE_CHECKING :
25+ if TYPE_CHECKING : # pragma: no cover
2626 from .cmd2 import Cmd
2727
2828
Original file line number Diff line number Diff line change 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
1518from .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+
7894def test_apcustom_usage () -> None :
7995 usage = "A custom usage statement"
8096 parser = Cmd2ArgumentParser (usage = usage )
Original file line number Diff line number Diff 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
987998class RedirCompType (enum .Enum ):
988999 SHELL_CMD = (1 ,)
You can’t perform that action at this time.
0 commit comments