@@ -1390,14 +1390,11 @@ def test_echo(capsys):
1390
1390
assert app ._current_script_dir is None
1391
1391
assert out .startswith ('{}{}\n ' .format (app .prompt , command ) + 'history [arg]: lists past commands issued' )
1392
1392
1393
- #@pytest.mark.parametrize('rawinput', [True, False])
1394
- def test_piped_input_echo_false (capsys ):
1393
+ def test_piped_input_echo_false_rawinput_false (capsys ):
1395
1394
command = 'set'
1396
1395
1397
- # hack up stdin
1396
+ # mock up the input
1398
1397
fakein = io .StringIO (command )
1399
- #realin = sys.stdin
1400
- #sys.stdin = fakein
1401
1398
1402
1399
# run the cmdloop, which should pull input from stdin
1403
1400
app = cmd2 .Cmd (stdin = fakein )
@@ -1407,21 +1404,50 @@ def test_piped_input_echo_false(capsys):
1407
1404
app ._cmdloop ()
1408
1405
out , err = capsys .readouterr ()
1409
1406
1410
- # put stdin back
1411
- #sys.stdin = realin
1412
-
1413
1407
firstline = out .splitlines ()[0 ]
1414
1408
assert firstline == 'abbrev: False'
1415
1409
assert not '{}{}' .format (app .prompt , command ) in out
1416
1410
1417
- #@pytest.mark.parametrize('rawinput', [True, False])
1418
- def test_piped_input_echo_true (capsys ):
1411
+ #
1412
+ # WARNING:
1413
+ #
1414
+ # this test passes, and validates the proper behavior of
1415
+ # cmd2.pseudo_raw_input() when use_rawinput = True
1416
+ #
1417
+ # However, there is only one way to patch/mock/hack input()
1418
+ # or raw_input() for testing: that is to change the
1419
+ # sys.stdin file descriptor. This results in unpredictable
1420
+ # failures when 'pytest -n8' parallelizes tests.
1421
+ #
1422
+ # @pytest.mark.parametrize('rawinput', [True, False])
1423
+ # def test_piped_input_echo_false_stdin_hack(capsys, rawinput):
1424
+ # command = 'set'
1425
+ #
1426
+ # # hack up stdin
1427
+ # fakein = io.StringIO(command)
1428
+ # realin = sys.stdin
1429
+ # sys.stdin = fakein
1430
+ #
1431
+ # # run the cmdloop, which should pull input from stdin
1432
+ # app = cmd2.Cmd(stdin=fakein)
1433
+ # app.use_rawinput = rawinput
1434
+ # app.echo = False
1435
+ # app.abbrev = False
1436
+ # app._cmdloop()
1437
+ # out, err = capsys.readouterr()
1438
+ #
1439
+ # # put stdin back
1440
+ # sys.stdin = realin
1441
+ #
1442
+ # firstline = out.splitlines()[0]
1443
+ # assert firstline == 'abbrev: False'
1444
+ # assert not '{}{}'.format(app.prompt, command) in out
1445
+
1446
+ def test_piped_input_echo_true_rawinput_false (capsys ):
1419
1447
command = 'set'
1420
1448
1421
- # hack up stdin
1449
+ # mock up the input
1422
1450
fakein = io .StringIO (command )
1423
- # realin = sys.stdin
1424
- # sys.stdin = fakein
1425
1451
1426
1452
# run the cmdloop, which should pull input from stdin
1427
1453
app = cmd2 .Cmd (stdin = fakein )
@@ -1431,13 +1457,45 @@ def test_piped_input_echo_true(capsys):
1431
1457
app ._cmdloop ()
1432
1458
out , err = capsys .readouterr ()
1433
1459
1434
- # put stdin back
1435
- # sys.stdin = realin
1436
-
1437
1460
out = out .splitlines ()
1438
1461
assert out [0 ] == '{}{}' .format (app .prompt , command )
1439
1462
assert out [1 ] == 'abbrev: False'
1440
-
1463
+
1464
+ #
1465
+ # WARNING:
1466
+ #
1467
+ # this test passes, and validates the proper behavior of
1468
+ # cmd2.pseudo_raw_input() when use_rawinput = True
1469
+ #
1470
+ # However, there is only one way to patch/mock/hack input()
1471
+ # or raw_input() for testing: that is to change the
1472
+ # sys.stdin file descriptor. This results in unpredictable
1473
+ # failures when 'pytest -n8' parallelizes tests.
1474
+ #
1475
+ # @pytest.mark.parametrize('rawinput', [True, False])
1476
+ # def test_piped_input_echo_true_stdin_hack(capsys, rawinput):
1477
+ # command = 'set'
1478
+ #
1479
+ # # hack up stdin
1480
+ # fakein = io.StringIO(command)
1481
+ # realin = sys.stdin
1482
+ # sys.stdin = fakein
1483
+ #
1484
+ # # run the cmdloop, which should pull input from stdin
1485
+ # app = cmd2.Cmd()
1486
+ # app.use_rawinput = rawinput
1487
+ # app.echo = True
1488
+ # app.abbrev = False
1489
+ # app._cmdloop()
1490
+ # out, err = capsys.readouterr()
1491
+ #
1492
+ # # put stdin back
1493
+ # sys.stdin = realin
1494
+ #
1495
+ # out = out.splitlines()
1496
+ # assert out[0] == '{}{}'.format(app.prompt, command)
1497
+ # assert out[1] == 'abbrev: False'
1498
+
1441
1499
def test_raw_input (base_app ):
1442
1500
base_app .use_raw_input = True
1443
1501
fake_input = 'quit'
0 commit comments