diff options
-rw-r--r-- | docs/requirements.txt | 1 | ||||
-rwxr-xr-x | examples/persistent_history.py | 1 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | tests/test_cmd2.py | 27 | ||||
-rw-r--r-- | tox.ini | 8 |
5 files changed, 38 insertions, 1 deletions
diff --git a/docs/requirements.txt b/docs/requirements.txt index fa4e3570..b50df7d1 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,4 @@ pyparsing six pyperclip +contextlib2 diff --git a/examples/persistent_history.py b/examples/persistent_history.py index 21a2cbf3..e3f646bf 100755 --- a/examples/persistent_history.py +++ b/examples/persistent_history.py @@ -13,6 +13,7 @@ class Cmd2PersistentHistory(cmd2.Cmd): def __init__(self): """""" cmd2.Cmd.__init__(self, persistent_history_file='~/.persistent_history.cmd2', persistent_history_length=500) + self.prompt = 'ph> ' # ... your class code here ... @@ -77,7 +77,7 @@ if sys.version_info < (3, 0): INSTALL_REQUIRES += ['subprocess32'] # unittest.mock was added in Python 3.3. mock is a backport of unittest.mock to all versions of Python -TESTS_REQUIRE = ['mock', 'pytest'] +TESTS_REQUIRE = ['mock', 'pytest', 'pexpect'] DOCS_REQUIRE = ['sphinx', 'sphinx_rtd_theme', 'pyparsing', 'pyperclip', 'six'] setup( 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' + + @@ -13,6 +13,7 @@ setenv = deps = codecov mock + pexpect pyparsing pyperclip pytest @@ -28,6 +29,7 @@ commands = deps = codecov mock + pexpect pyparsing pyperclip pyreadline @@ -43,6 +45,7 @@ commands = [testenv:py34] deps = mock + pexpect pyparsing pyperclip pytest @@ -53,6 +56,7 @@ commands = py.test -v -n2 [testenv:py35] deps = mock + pexpect pyparsing pyperclip pytest @@ -63,6 +67,7 @@ commands = py.test -v -n2 [testenv:py35-win] deps = mock + pexpect pyparsing pyperclip pyreadline @@ -75,6 +80,7 @@ commands = py.test -v -n2 deps = codecov mock + pexpect pyparsing pyperclip pytest @@ -88,6 +94,7 @@ commands = [testenv:py36-win] deps = mock + pexpect pyparsing pyperclip pyreadline @@ -99,6 +106,7 @@ commands = py.test -v -n2 [testenv:py37] deps = mock + pexpect pyparsing pyperclip pytest |