7
7
"""
8
8
import os
9
9
import sys
10
+ import io
10
11
import tempfile
11
12
12
13
import mock
@@ -849,6 +850,7 @@ def test_cmdloop_without_rawinput():
849
850
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
850
851
app = cmd2 .Cmd ()
851
852
app .use_rawinput = False
853
+ app .echo = False
852
854
app .intro = 'Hello World, this is an intro ...'
853
855
app .stdout = StdOut ()
854
856
@@ -858,7 +860,7 @@ def test_cmdloop_without_rawinput():
858
860
859
861
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
860
862
testargs = ["prog" ]
861
- expected = app .intro + '\n {}' . format ( app . prompt )
863
+ expected = app .intro + '\n '
862
864
with mock .patch .object (sys , 'argv' , testargs ):
863
865
# Run the command loop
864
866
app .cmdloop ()
@@ -1388,7 +1390,54 @@ def test_echo(capsys):
1388
1390
assert app ._current_script_dir is None
1389
1391
assert out .startswith ('{}{}\n ' .format (app .prompt , command ) + 'history [arg]: lists past commands issued' )
1390
1392
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
1391
1436
1437
+ out = out .splitlines ()
1438
+ assert out [0 ] == '{}{}' .format (app .prompt , command )
1439
+ assert out [1 ] == 'abbrev: False'
1440
+
1392
1441
def test_raw_input (base_app ):
1393
1442
base_app .use_raw_input = True
1394
1443
fake_input = 'quit'
0 commit comments