summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-09 00:07:06 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-02-09 00:07:06 -0500
commit6eb8dde0d33df2d73f9c7ff75c6beddae5453ddd (patch)
tree44cbbfc579efa655df4167e88d568ec3d8c85af4 /tests/test_cmd2.py
parent303e9cb734d217fe4f142040518e3dd7a2a2b3ee (diff)
downloadcmd2-git-6eb8dde0d33df2d73f9c7ff75c6beddae5453ddd.tar.gz
First past at unit test for persistent history feature
Added pexpect to modules required for running unit tests. This opens the door for carefully crafted complex unit tests to verify intricate behavior. Tests like this are somewhat painful to write and slow to execute. However, they can enable testing complicated interactive behavior that we otherwise probably would not be able to test.
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 5f56803d..454fdc1f 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
@@ -1525,3 +1526,29 @@ def test_poutput_none(base_app):
out = base_app.stdout.buffer
expected = ''
assert out == expected
+
+
+def test_persistent_history(request):
+ test_dir = os.path.dirname(request.module.__file__)
+ persistent_app = os.path.join(test_dir, '..', 'examples', 'persistent_history.py')
+
+ # STart an instance of the persistent history example and send it a few commands
+ child = pexpect.spawn(persistent_app)
+ 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(persistent_app)
+ child2.expect(prompt)
+ child2.send(up_arrow)
+ child2.expect('quit', timeout=5)
+ assert child2.after == b'quit'
+
+