@@ -137,22 +137,6 @@ def do_alternate(self, args) -> None:
137137 '/home/other user/tests' ,
138138]
139139
140- # Dictionary used with flag based completion functions
141- flag_dict = {
142- # Tab complete food items after -f and --food flag in command line
143- '-f' : food_item_strs ,
144- '--food' : food_item_strs ,
145- # Tab complete sport items after -s and --sport flag in command line
146- '-s' : sport_item_strs ,
147- '--sport' : sport_item_strs ,
148- }
149-
150- # Dictionary used with index based completion functions
151- index_dict = {
152- 1 : food_item_strs , # Tab complete food items at index 1 in command line
153- 2 : sport_item_strs , # Tab complete sport items at index 2 in command line
154- }
155-
156140
157141class CompletionsExample (cmd2 .Cmd ):
158142 """Example cmd2 application used to exercise tab completion tests"""
@@ -720,107 +704,6 @@ def test_delimiter_completion_nomatch(cmd2_app) -> None:
720704 assert not completions
721705
722706
723- def test_flag_based_completion (cmd2_app ) -> None :
724- text = 'P'
725- line = f'list_food -f { text } '
726- endidx = len (line )
727- begidx = endidx - len (text )
728-
729- expected = ['Pizza' , 'Potato' ]
730- completions = cmd2_app .flag_based_complete (text , line , begidx , endidx , flag_dict )
731- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
732-
733-
734- def test_flag_based_completion_nomatch (cmd2_app ) -> None :
735- text = 'q'
736- line = f'list_food -f { text } '
737- endidx = len (line )
738- begidx = endidx - len (text )
739-
740- completions = cmd2_app .flag_based_complete (text , line , begidx , endidx , flag_dict )
741- assert not completions
742-
743-
744- def test_flag_based_default_completer (cmd2_app , request ) -> None :
745- test_dir = os .path .dirname (request .module .__file__ )
746-
747- text = os .path .join (test_dir , 'c' )
748- line = f'list_food { text } '
749-
750- endidx = len (line )
751- begidx = endidx - len (text )
752-
753- expected = [text + 'onftest.py' ]
754- completions = cmd2_app .flag_based_complete (text , line , begidx , endidx , flag_dict , all_else = cmd2_app .path_complete )
755- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
756-
757-
758- def test_flag_based_callable_completer (cmd2_app , request ) -> None :
759- test_dir = os .path .dirname (request .module .__file__ )
760-
761- text = os .path .join (test_dir , 'c' )
762- line = f'list_food -o { text } '
763-
764- endidx = len (line )
765- begidx = endidx - len (text )
766-
767- flag_dict ['-o' ] = cmd2_app .path_complete
768-
769- expected = [text + 'onftest.py' ]
770- completions = cmd2_app .flag_based_complete (text , line , begidx , endidx , flag_dict )
771- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
772-
773-
774- def test_index_based_completion (cmd2_app ) -> None :
775- text = ''
776- line = f'command Pizza { text } '
777- endidx = len (line )
778- begidx = endidx - len (text )
779-
780- expected = sport_item_strs
781- completions = cmd2_app .index_based_complete (text , line , begidx , endidx , index_dict )
782- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
783-
784-
785- def test_index_based_completion_nomatch (cmd2_app ) -> None :
786- text = 'q'
787- line = f'command { text } '
788- endidx = len (line )
789- begidx = endidx - len (text )
790- completions = cmd2_app .index_based_complete (text , line , begidx , endidx , index_dict )
791- assert not completions
792-
793-
794- def test_index_based_default_completer (cmd2_app , request ) -> None :
795- test_dir = os .path .dirname (request .module .__file__ )
796-
797- text = os .path .join (test_dir , 'c' )
798- line = f'command Pizza Bat Computer { text } '
799-
800- endidx = len (line )
801- begidx = endidx - len (text )
802-
803- expected = [text + 'onftest.py' ]
804- completions = cmd2_app .index_based_complete (text , line , begidx , endidx , index_dict , all_else = cmd2_app .path_complete )
805- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
806-
807-
808- def test_index_based_callable_completer (cmd2_app , request ) -> None :
809- test_dir = os .path .dirname (request .module .__file__ )
810-
811- text = os .path .join (test_dir , 'c' )
812- line = f'command Pizza Bat { text } '
813-
814- endidx = len (line )
815- begidx = endidx - len (text )
816-
817- index_dict [3 ] = cmd2_app .path_complete
818-
819- expected = [text + 'onftest.py' ]
820- completions = cmd2_app .index_based_complete (text , line , begidx , endidx , index_dict )
821- assert completions .to_strings () == Completions .from_values (expected ).to_strings ()
822-
823-
824707def test_tokens_for_completion_quoted (cmd2_app ) -> None :
825708 text = 'Pi'
826709 line = f'list_food "{ text } "'
0 commit comments