diff options
author | jquast <contact@jeffquast.com> | 2014-06-28 21:37:38 -0700 |
---|---|---|
committer | Thomas Kluyver <takowl@gmail.com> | 2015-10-04 09:21:02 +0100 |
commit | 1ba286fc604ad6665d7cc3edbb2db3bff54b7a82 (patch) | |
tree | f6a2bdbd79d7c24f719c16dd40bc4852c4421ccb /tests | |
parent | 26ff2f390a8d3179fef2bf1dba715fa0dcf886e8 (diff) | |
download | pexpect-git-1ba286fc604ad6665d7cc3edbb2db3bff54b7a82.tar.gz |
This resolves two issues with replwrap,
* for multiple commands, such as in
``'\n'.join((cmd, cmd2))``, cmd2 and beyond
previously used a ``timeout`` of 1, instead of
the specified or default ``timeout``.
* furthermore, the output of multi-command output
was discarded, only the last-most command output
was received. Resolved by joining the result of
``self.child.before``.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_replwrap.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/tests/test_replwrap.py b/tests/test_replwrap.py index 28c7599..6e56af0 100644 --- a/tests/test_replwrap.py +++ b/tests/test_replwrap.py @@ -6,6 +6,8 @@ import os import pexpect from pexpect import replwrap +skip_pypy = "This test fails on PyPy because of REPL differences" + class REPLWrapTestCase(unittest.TestCase): def setUp(self): @@ -25,10 +27,24 @@ class REPLWrapTestCase(unittest.TestCase): res = bash.run_command("time") assert 'real' in res, res - # PAGER should be set to cat, otherwise man hangs + def test_pager_as_cat(self): + " PAGER is set to cat, to prevent timeout in ``man sleep``. " + bash = replwrap.bash() res = bash.run_command('man sleep', timeout=5) assert 'SLEEP' in res, res + def test_long_running_multiline(self): + " ensure the default timeout is used for multi-line commands. " + bash = replwrap.bash() + res = bash.run_command("echo begin\r\nsleep 2\r\necho done") + self.assertEqual(res.strip().splitlines(), ['begin', 'done']) + + def test_long_running_continuation(self): + " also ensure timeout when used within continuation prompts. " + bash = replwrap.bash() + res = bash.run_command("echo begin\\\n;sleep 2\r\necho done") + self.assertEqual(res.strip().splitlines(), ['begin', 'done']) + def test_multiline(self): bash = replwrap.bash() res = bash.run_command("echo '1 2\n3 4'") @@ -57,7 +73,7 @@ class REPLWrapTestCase(unittest.TestCase): def test_python(self): if platform.python_implementation() == 'PyPy': - raise unittest.SkipTest("This test fails on PyPy because of REPL differences") + raise unittest.SkipTest(skip_pypy) p = replwrap.python() res = p.run_command('4+7') @@ -68,7 +84,7 @@ class REPLWrapTestCase(unittest.TestCase): def test_no_change_prompt(self): if platform.python_implementation() == 'PyPy': - raise unittest.SkipTest("This test fails on PyPy because of REPL differences") + raise unittest.SkipTest(skip_pypy) child = pexpect.spawnu('python', echo=False, timeout=5) # prompt_change=None should mean no prompt change @@ -79,6 +95,5 @@ class REPLWrapTestCase(unittest.TestCase): res = py.run_command("for a in range(3): print(a)\n") assert res.strip().splitlines() == ['0', '1', '2'] - if __name__ == '__main__': unittest.main() |