@@ -1750,13 +1750,16 @@ def test_select_choice_tty(outsim_app, monkeypatch) -> None:
17501750 choice_mock = mock .MagicMock (name = 'choice' , return_value = 'sweet' )
17511751 monkeypatch .setattr ("cmd2.cmd2.choice" , choice_mock )
17521752
1753- # Mock isatty to be True for both stdin and stdout
1754- monkeypatch .setattr (outsim_app .stdin , "isatty" , lambda : True )
1755- monkeypatch .setattr (outsim_app .stdout , "isatty" , lambda : True )
1756-
17571753 prompt = 'Sauce? '
17581754 options = ['sweet' , 'salty' ]
1759- result = outsim_app .select (options , prompt )
1755+
1756+ with create_pipe_input () as pipe_input :
1757+ outsim_app .main_session = PromptSession (
1758+ input = pipe_input ,
1759+ output = DummyOutput (),
1760+ )
1761+
1762+ result = outsim_app .select (options , prompt )
17601763
17611764 assert result == 'sweet'
17621765 choice_mock .assert_called_once_with (message = prompt , options = [('sweet' , 'sweet' ), ('salty' , 'salty' )])
@@ -1767,17 +1770,20 @@ def test_select_choice_tty_ctrl_c(outsim_app, monkeypatch) -> None:
17671770 choice_mock = mock .MagicMock (name = 'choice' , side_effect = KeyboardInterrupt )
17681771 monkeypatch .setattr ("cmd2.cmd2.choice" , choice_mock )
17691772
1770- # Mock isatty to be True for both stdin and stdout
1771- monkeypatch .setattr (outsim_app .stdin , "isatty" , lambda : True )
1772- monkeypatch .setattr (outsim_app .stdout , "isatty" , lambda : True )
1773-
17741773 prompt = 'Sauce? '
17751774 options = ['sweet' , 'salty' ]
17761775
1777- with pytest .raises (KeyboardInterrupt ):
1778- outsim_app .select (options , prompt )
1776+ # Mock isatty to be True for both stdin and stdout
1777+ with create_pipe_input () as pipe_input :
1778+ outsim_app .main_session = PromptSession (
1779+ input = pipe_input ,
1780+ output = DummyOutput (),
1781+ )
17791782
1780- out = outsim_app .stdout .getvalue ()
1783+ with pytest .raises (KeyboardInterrupt ):
1784+ outsim_app .select (options , prompt )
1785+
1786+ out = outsim_app .stdout .getvalue ()
17811787 assert out .rstrip ().endswith ('^C' )
17821788
17831789
0 commit comments