@@ -902,11 +902,6 @@ class RedirCompType(enum.Enum):
902902 DEFAULT = 3 ,
903903 NONE = 4
904904
905- """
906- fake > >
907- fake | grep > file
908- fake | grep > file >
909- """
910905
911906@pytest .mark .parametrize ('line, comp_type' , [
912907 ('fake' , RedirCompType .DEFAULT ),
@@ -933,31 +928,40 @@ class RedirCompType(enum.Enum):
933928 ('fake > file >>' , RedirCompType .NONE ),
934929])
935930def test_redirect_complete (cmd2_app , monkeypatch , line , comp_type ):
936- shell_cmd_complete_mock = mock .MagicMock (name = 'shell_cmd_complete' )
937- monkeypatch .setattr ("cmd2.Cmd.shell_cmd_complete" , shell_cmd_complete_mock )
938-
939- path_complete_mock = mock .MagicMock (name = 'path_complete' )
940- monkeypatch .setattr ("cmd2.Cmd.path_complete" , path_complete_mock )
941-
942- default_complete_mock = mock .MagicMock (name = 'fake_completer' )
943-
944- text = ''
945- line = '{} {}' .format (line , text )
946- endidx = len (line )
947- begidx = endidx - len (text )
931+ # Test both cases of allow_redirection
932+ cmd2_app .allow_redirection = True
933+ for count in range (2 ):
934+ shell_cmd_complete_mock = mock .MagicMock (name = 'shell_cmd_complete' )
935+ monkeypatch .setattr ("cmd2.Cmd.shell_cmd_complete" , shell_cmd_complete_mock )
936+
937+ path_complete_mock = mock .MagicMock (name = 'path_complete' )
938+ monkeypatch .setattr ("cmd2.Cmd.path_complete" , path_complete_mock )
939+
940+ default_complete_mock = mock .MagicMock (name = 'fake_completer' )
941+
942+ text = ''
943+ line = '{} {}' .format (line , text )
944+ endidx = len (line )
945+ begidx = endidx - len (text )
946+
947+ cmd2_app ._redirect_complete (text , line , begidx , endidx , default_complete_mock )
948+
949+ if comp_type == RedirCompType .SHELL_CMD :
950+ shell_cmd_complete_mock .assert_called_once ()
951+ elif comp_type == RedirCompType .PATH :
952+ path_complete_mock .assert_called_once ()
953+ elif comp_type == RedirCompType .DEFAULT :
954+ default_complete_mock .assert_called_once ()
955+ else :
956+ shell_cmd_complete_mock .assert_not_called ()
957+ path_complete_mock .assert_not_called ()
958+ default_complete_mock .assert_not_called ()
948959
949- cmd2_app ._redirect_complete (text , line , begidx , endidx , default_complete_mock )
960+ # Do the next test with allow_redirection as False
961+ cmd2_app .allow_redirection = False
962+ if comp_type != RedirCompType .DEFAULT :
963+ comp_type = RedirCompType .NONE
950964
951- if comp_type == RedirCompType .SHELL_CMD :
952- shell_cmd_complete_mock .assert_called_once ()
953- elif comp_type == RedirCompType .PATH :
954- path_complete_mock .assert_called_once ()
955- elif comp_type == RedirCompType .DEFAULT :
956- default_complete_mock .assert_called_once ()
957- else :
958- shell_cmd_complete_mock .assert_not_called ()
959- path_complete_mock .assert_not_called ()
960- default_complete_mock .assert_not_called ()
961965
962966def test_complete_set_value (cmd2_app ):
963967 text = ''
0 commit comments