66Released under MIT license, see LICENSE file
77"""
88import argparse
9+ import builtins
910from code import InteractiveConsole
1011import os
1112import sys
1213import io
1314import tempfile
1415
1516import pytest
16- import six
17- import six .moves as sm
1817
1918# Python 3.5 had some regressions in the unitest.mock module, so use 3rd party mock if available
2019try :
@@ -839,7 +838,7 @@ def test_base_cmdloop_without_queue():
839838
840839 # Mock out the input call so we don't actually wait for a user's response on stdin
841840 m = mock .MagicMock (name = 'input' , return_value = 'quit' )
842- sm .input = m
841+ builtins .input = m
843842
844843 # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
845844 testargs = ["prog" ]
@@ -861,7 +860,7 @@ def test_cmdloop_without_rawinput():
861860
862861 # Mock out the input call so we don't actually wait for a user's response on stdin
863862 m = mock .MagicMock (name = 'input' , return_value = 'quit' )
864- sm .input = m
863+ builtins .input = m
865864
866865 # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
867866 testargs = ["prog" ]
@@ -916,7 +915,7 @@ def test_interrupt_quit(say_app):
916915 # Mock out the input call so we don't actually wait for a user's response on stdin
917916 m = mock .MagicMock (name = 'input' )
918917 m .side_effect = ['say hello' , KeyboardInterrupt (), 'say goodbye' , 'eof' ]
919- sm .input = m
918+ builtins .input = m
920919
921920 say_app .cmdloop ()
922921
@@ -930,7 +929,7 @@ def test_interrupt_noquit(say_app):
930929 # Mock out the input call so we don't actually wait for a user's response on stdin
931930 m = mock .MagicMock (name = 'input' )
932931 m .side_effect = ['say hello' , KeyboardInterrupt (), 'say goodbye' , 'eof' ]
933- sm .input = m
932+ builtins .input = m
934933
935934 say_app .cmdloop ()
936935
@@ -1189,7 +1188,7 @@ def select_app():
11891188def test_select_options (select_app ):
11901189 # Mock out the input call so we don't actually wait for a user's response on stdin
11911190 m = mock .MagicMock (name = 'input' , return_value = '2' )
1192- sm .input = m
1191+ builtins .input = m
11931192
11941193 food = 'bacon'
11951194 out = run_cmd (select_app , "eat {}" .format (food ))
@@ -1210,7 +1209,7 @@ def test_select_invalid_option(select_app):
12101209 m = mock .MagicMock (name = 'input' )
12111210 # If side_effect is an iterable then each call to the mock will return the next value from the iterable.
12121211 m .side_effect = ['3' , '1' ] # First pass and invalid selection, then pass a valid one
1213- sm .input = m
1212+ builtins .input = m
12141213
12151214 food = 'fish'
12161215 out = run_cmd (select_app , "eat {}" .format (food ))
@@ -1232,7 +1231,7 @@ def test_select_invalid_option(select_app):
12321231def test_select_list_of_strings (select_app ):
12331232 # Mock out the input call so we don't actually wait for a user's response on stdin
12341233 m = mock .MagicMock (name = 'input' , return_value = '2' )
1235- sm .input = m
1234+ builtins .input = m
12361235
12371236 out = run_cmd (select_app , "study" )
12381237 expected = normalize ("""
@@ -1250,7 +1249,7 @@ def test_select_list_of_strings(select_app):
12501249def test_select_list_of_tuples (select_app ):
12511250 # Mock out the input call so we don't actually wait for a user's response on stdin
12521251 m = mock .MagicMock (name = 'input' , return_value = '2' )
1253- sm .input = m
1252+ builtins .input = m
12541253
12551254 out = run_cmd (select_app , "procrastinate" )
12561255 expected = normalize ("""
@@ -1269,7 +1268,7 @@ def test_select_list_of_tuples(select_app):
12691268def test_select_uneven_list_of_tuples (select_app ):
12701269 # Mock out the input call so we don't actually wait for a user's response on stdin
12711270 m = mock .MagicMock (name = 'input' , return_value = '2' )
1272- sm .input = m
1271+ builtins .input = m
12731272
12741273 out = run_cmd (select_app , "play" )
12751274 expected = normalize ("""
@@ -1352,7 +1351,7 @@ def test_multiline_complete_empty_statement_raises_exception(multiline_app):
13521351def test_multiline_complete_statement_without_terminator (multiline_app ):
13531352 # Mock out the input call so we don't actually wait for a user's response on stdin when it looks for more input
13541353 m = mock .MagicMock (name = 'input' , return_value = '\n ' )
1355- sm .input = m
1354+ builtins .input = m
13561355
13571356 command = 'orate'
13581357 args = 'hello world'
@@ -1452,10 +1451,8 @@ def test_echo(capsys):
14521451def test_pseudo_raw_input_tty_rawinput_true ():
14531452 # use context managers so original functions get put back when we are done
14541453 # we dont use decorators because we need m_input for the assertion
1455- with mock .patch ('sys.stdin.isatty' ,
1456- mock .MagicMock (name = 'isatty' , return_value = True )):
1457- with mock .patch ('six.moves.input' ,
1458- mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ])) as m_input :
1454+ with mock .patch ('sys.stdin.isatty' , mock .MagicMock (name = 'isatty' , return_value = True )):
1455+ with mock .patch ('builtins.input' , mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ])) as m_input :
14591456 # run the cmdloop, which should pull input from our mocks
14601457 app = cmd2 .Cmd ()
14611458 app .use_rawinput = True
@@ -1498,21 +1495,17 @@ def piped_rawinput_true(capsys, echo, command):
14981495 out , err = capsys .readouterr ()
14991496 return (app , out )
15001497
1501- # using the decorator puts the original function at six.moves.input
1502- # back when this method returns
1503- @mock .patch ('six.moves.input' ,
1504- mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ]))
1498+ # using the decorator puts the original input function back when this unit test returns
1499+ @mock .patch ('builtins.input' , mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ]))
15051500def test_pseudo_raw_input_piped_rawinput_true_echo_true (capsys ):
15061501 command = 'set'
15071502 app , out = piped_rawinput_true (capsys , True , command )
15081503 out = out .splitlines ()
15091504 assert out [0 ] == '{}{}' .format (app .prompt , command )
15101505 assert out [1 ].startswith ('colors:' )
15111506
1512- # using the decorator puts the original function at six.moves.input
1513- # back when this method returns
1514- @mock .patch ('six.moves.input' ,
1515- mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ]))
1507+ # using the decorator puts the original input function back when this unit test returns
1508+ @mock .patch ('builtins.input' , mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ]))
15161509def test_pseudo_raw_input_piped_rawinput_true_echo_false (capsys ):
15171510 command = 'set'
15181511 app , out = piped_rawinput_true (capsys , False , command )
@@ -1554,7 +1547,7 @@ def test_raw_input(base_app):
15541547
15551548 # Mock out the input call so we don't actually wait for a user's response on stdin
15561549 m = mock .Mock (name = 'input' , return_value = fake_input )
1557- sm .input = m
1550+ builtins .input = m
15581551
15591552 line = base_app .pseudo_raw_input ('(cmd2)' )
15601553 assert line == fake_input
0 commit comments