77"""
88import os
99import sys
10+ import io
1011import tempfile
1112
1213import mock
@@ -849,6 +850,7 @@ def test_cmdloop_without_rawinput():
849850 # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
850851 app = cmd2 .Cmd ()
851852 app .use_rawinput = False
853+ app .echo = False
852854 app .intro = 'Hello World, this is an intro ...'
853855 app .stdout = StdOut ()
854856
@@ -858,7 +860,7 @@ def test_cmdloop_without_rawinput():
858860
859861 # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
860862 testargs = ["prog" ]
861- expected = app .intro + '\n {}' . format ( app . prompt )
863+ expected = app .intro + '\n '
862864 with mock .patch .object (sys , 'argv' , testargs ):
863865 # Run the command loop
864866 app .cmdloop ()
@@ -1388,7 +1390,54 @@ def test_echo(capsys):
13881390 assert app ._current_script_dir is None
13891391 assert out .startswith ('{}{}\n ' .format (app .prompt , command ) + 'history [arg]: lists past commands issued' )
13901392
1393+ #@pytest.mark.parametrize('rawinput', [True, False])
1394+ def test_piped_input_echo_false (capsys ):
1395+ command = 'set'
1396+
1397+ # hack up stdin
1398+ fakein = io .StringIO (command )
1399+ #realin = sys.stdin
1400+ #sys.stdin = fakein
1401+
1402+ # run the cmdloop, which should pull input from stdin
1403+ app = cmd2 .Cmd (stdin = fakein )
1404+ app .use_rawinput = False
1405+ app .echo = False
1406+ app .abbrev = False
1407+ app ._cmdloop ()
1408+ out , err = capsys .readouterr ()
1409+
1410+ # put stdin back
1411+ #sys.stdin = realin
1412+
1413+ firstline = out .splitlines ()[0 ]
1414+ assert firstline == 'abbrev: False'
1415+ assert not '{}{}' .format (app .prompt , command ) in out
1416+
1417+ #@pytest.mark.parametrize('rawinput', [True, False])
1418+ def test_piped_input_echo_true (capsys ):
1419+ command = 'set'
1420+
1421+ # hack up stdin
1422+ fakein = io .StringIO (command )
1423+ # realin = sys.stdin
1424+ # sys.stdin = fakein
1425+
1426+ # run the cmdloop, which should pull input from stdin
1427+ app = cmd2 .Cmd (stdin = fakein )
1428+ app .use_rawinput = False
1429+ app .echo = True
1430+ app .abbrev = False
1431+ app ._cmdloop ()
1432+ out , err = capsys .readouterr ()
1433+
1434+ # put stdin back
1435+ # sys.stdin = realin
13911436
1437+ out = out .splitlines ()
1438+ assert out [0 ] == '{}{}' .format (app .prompt , command )
1439+ assert out [1 ] == 'abbrev: False'
1440+
13921441def test_raw_input (base_app ):
13931442 base_app .use_raw_input = True
13941443 fake_input = 'quit'
0 commit comments