@@ -743,53 +743,57 @@ def test_base_cmdloop_with_startup_commands():
743743 expected = intro + '\n '
744744
745745 with mock .patch .object (sys , 'argv' , testargs ):
746- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
747746 app = CreateOutsimApp ()
748- app .use_rawinput = True
749747
750- # Run the command loop with custom intro
751- app .cmdloop (intro = intro )
748+ app .use_rawinput = True
749+
750+ # Run the command loop with custom intro
751+ app .cmdloop (intro = intro )
752752
753753 out = app .stdout .getvalue ()
754754 assert out == expected
755755
756756
757- def test_base_cmdloop_without_startup_commands (outsim_app ):
758- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
759- outsim_app .use_rawinput = True
760- outsim_app .intro = 'Hello World, this is an intro ...'
757+ def test_base_cmdloop_without_startup_commands ():
758+ # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
759+ testargs = ["prog" ]
760+ with mock .patch .object (sys , 'argv' , testargs ):
761+ app = CreateOutsimApp ()
762+
763+ app .use_rawinput = True
764+ app .intro = 'Hello World, this is an intro ...'
761765
762766 # Mock out the input call so we don't actually wait for a user's response on stdin
763767 m = mock .MagicMock (name = 'input' , return_value = 'quit' )
764768 builtins .input = m
765769
770+ expected = app .intro + '\n '
771+
772+ # Run the command loop
773+ app .cmdloop ()
774+ out = app .stdout .getvalue ()
775+ assert out == expected
776+
777+
778+ def test_cmdloop_without_rawinput ():
766779 # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
767780 testargs = ["prog" ]
768- expected = outsim_app .intro + '\n '
769781 with mock .patch .object (sys , 'argv' , testargs ):
770- # Run the command loop
771- outsim_app .cmdloop ()
772- out = outsim_app .stdout .getvalue ()
773- assert out == expected
774-
782+ app = CreateOutsimApp ()
775783
776- def test_cmdloop_without_rawinput (outsim_app ):
777- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
778- outsim_app .use_rawinput = False
779- outsim_app .echo = False
780- outsim_app .intro = 'Hello World, this is an intro ...'
784+ app .use_rawinput = False
785+ app .echo = False
786+ app .intro = 'Hello World, this is an intro ...'
781787
782788 # Mock out the input call so we don't actually wait for a user's response on stdin
783789 m = mock .MagicMock (name = 'input' , return_value = 'quit' )
784790 builtins .input = m
785791
786- # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
787- testargs = ["prog" ]
788- expected = outsim_app .intro + '\n '
789- with mock .patch .object (sys , 'argv' , testargs ):
790- with pytest .raises (OSError ):
791- outsim_app .cmdloop ()
792- out = outsim_app .stdout .getvalue ()
792+ expected = app .intro + '\n '
793+
794+ with pytest .raises (OSError ):
795+ app .cmdloop ()
796+ out = app .stdout .getvalue ()
793797 assert out == expected
794798
795799class HookFailureApp (cmd2 .Cmd ):
@@ -1399,7 +1403,7 @@ def test_pseudo_raw_input_tty_rawinput_true():
13991403 with mock .patch ('sys.stdin.isatty' , mock .MagicMock (name = 'isatty' , return_value = True )):
14001404 with mock .patch ('builtins.input' , mock .MagicMock (name = 'input' , side_effect = ['set' , EOFError ])) as m_input :
14011405 # run the cmdloop, which should pull input from our mocks
1402- app = cmd2 .Cmd ()
1406+ app = cmd2 .Cmd (allow_cli_args = False )
14031407 app .use_rawinput = True
14041408 app ._cmdloop ()
14051409 # because we mocked the input() call, we won't get the prompt
@@ -1418,7 +1422,7 @@ def test_pseudo_raw_input_tty_rawinput_false():
14181422 fakein .readline = mreadline
14191423
14201424 # run the cmdloop, telling it where to get input from
1421- app = cmd2 .Cmd (stdin = fakein )
1425+ app = cmd2 .Cmd (stdin = fakein , allow_cli_args = False )
14221426 app .use_rawinput = False
14231427 app ._cmdloop ()
14241428
@@ -1432,7 +1436,7 @@ def test_pseudo_raw_input_tty_rawinput_false():
14321436# the next helper function and two tests check for piped
14331437# input when use_rawinput is True.
14341438def piped_rawinput_true (capsys , echo , command ):
1435- app = cmd2 .Cmd ()
1439+ app = cmd2 .Cmd (allow_cli_args = False )
14361440 app .use_rawinput = True
14371441 app .echo = echo
14381442 # run the cmdloop, which should pull input from our mock
@@ -1462,8 +1466,7 @@ def test_pseudo_raw_input_piped_rawinput_true_echo_false(capsys):
14621466# input when use_rawinput=False
14631467def piped_rawinput_false (capsys , echo , command ):
14641468 fakein = io .StringIO (u'{}' .format (command ))
1465- # run the cmdloop, telling it where to get input from
1466- app = cmd2 .Cmd (stdin = fakein )
1469+ app = cmd2 .Cmd (stdin = fakein , allow_cli_args = False )
14671470 app .use_rawinput = False
14681471 app .echo = echo
14691472 app ._cmdloop ()
@@ -1931,7 +1934,7 @@ class ReplWithExitCode(cmd2.Cmd):
19311934 """ Example cmd2 application where we can specify an exit code when existing."""
19321935
19331936 def __init__ (self ):
1934- super ().__init__ ()
1937+ super ().__init__ (allow_cli_args = False )
19351938
19361939 @cmd2 .with_argument_list
19371940 def do_exit (self , arg_list ) -> bool :
@@ -1963,38 +1966,32 @@ def exit_code_repl():
19631966 return app
19641967
19651968def test_exit_code_default (exit_code_repl ):
1966- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
19671969 app = exit_code_repl
19681970 app .use_rawinput = True
19691971
19701972 # Mock out the input call so we don't actually wait for a user's response on stdin
19711973 m = mock .MagicMock (name = 'input' , return_value = 'exit' )
19721974 builtins .input = m
19731975
1974- # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
1975- testargs = ["prog" ]
19761976 expected = 'exiting with code: 0\n '
1977- with mock . patch . object ( sys , 'argv' , testargs ):
1978- # Run the command loop
1979- app .cmdloop ()
1977+
1978+ # Run the command loop
1979+ app .cmdloop ()
19801980 out = app .stdout .getvalue ()
19811981 assert out == expected
19821982
19831983def test_exit_code_nonzero (exit_code_repl ):
1984- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
19851984 app = exit_code_repl
19861985 app .use_rawinput = True
19871986
19881987 # Mock out the input call so we don't actually wait for a user's response on stdin
19891988 m = mock .MagicMock (name = 'input' , return_value = 'exit 23' )
19901989 builtins .input = m
19911990
1992- # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
1993- testargs = ["prog" ]
19941991 expected = 'exiting with code: 23\n '
1995- with mock . patch . object ( sys , 'argv' , testargs ):
1996- # Run the command loop
1997- app .cmdloop ()
1992+
1993+ # Run the command loop
1994+ app .cmdloop ()
19981995 out = app .stdout .getvalue ()
19991996 assert out == expected
20001997
0 commit comments