diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-02-11 23:23:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-11 23:23:51 -0500 |
commit | 4a765e16e64d0b8479921f2e36b4cb8b97db92b1 (patch) | |
tree | d5177fbf8ea7a732ae21febbf7e1c006e059ce2e /tests/test_cmd2.py | |
parent | 4895d5d8db4e57e2ef9a062473a8536f4f07f213 (diff) | |
parent | f3c6b1b32d614076dc17d2736ae1860d37a36cd5 (diff) | |
download | cmd2-git-4a765e16e64d0b8479921f2e36b4cb8b97db92b1.tar.gz |
Merge pull request #270 from python-cmd2/persistent_history
Added optional persistent readline history feature
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 186def65..ee9c1fc3 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -11,6 +11,7 @@ import io import tempfile import mock +import pexpect import pytest import six @@ -25,7 +26,7 @@ from conftest import run_cmd, normalize, BASE_HELP, HELP_HISTORY, SHORTCUTS_TXT, def test_ver(): - assert cmd2.__version__ == '0.8.0' + assert cmd2.__version__ == '0.8.1' def test_empty_statement(base_app): @@ -1525,3 +1526,37 @@ def test_poutput_none(base_app): out = base_app.stdout.buffer expected = '' assert out == expected + + +@pytest.mark.skipif(sys.platform == 'win32' or sys.platform.startswith('lin'), + reason="pexpect doesn't have a spawn() function on Windows and readline doesn't work on TravisCI") +def test_persistent_history(request): + """Will run on macOS to verify expected persistent history behavior.""" + test_dir = os.path.dirname(request.module.__file__) + persistent_app = os.path.join(test_dir, '..', 'examples', 'persistent_history.py') + + python = 'python3' + if six.PY2: + python = 'python2' + + command = '{} {}'.format(python, persistent_app) + + # Start an instance of the persistent history example and send it a few commands + child = pexpect.spawn(command) + prompt = 'ph> ' + child.expect(prompt) + child.sendline('help') + child.expect(prompt) + child.sendline('help history') + child.expect(prompt) + child.sendline('quit') + child.close() + + # Start a 2nd instance of the persistent history example and send it an up arrow to verify persistent history + up_arrow = '\x1b[A' + child2 = pexpect.spawn(command) + child2.expect(prompt) + child2.send(up_arrow) + child2.expect('quit') + assert child2.after == b'quit' + child2.close() |