diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2018-01-15 16:43:10 -0500 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2018-02-05 16:07:38 -0500 |
commit | fd7332f59e003a8ee658647f883d4b03018c5e5b (patch) | |
tree | 86f195b5ad8d0ff1ec5663c19c3b9de81c9334e5 /tests | |
parent | 28e82cda5056df20ec55995ea7fe66abd346f6bb (diff) | |
download | pexpect-git-fd7332f59e003a8ee658647f883d4b03018c5e5b.tar.gz |
optimize pty buffering and searching
Python strings are slow and expensive as buffers because they're
immutable; replace the output buffer with a StringIO/BytesIO
object
see: https://github.com/pexpect/pexpect/issues/438
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_expect.py | 8 | ||||
-rwxr-xr-x | tests/test_performance.py | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/test_expect.py b/tests/test_expect.py index dcf059b..ec55d43 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -400,6 +400,14 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): else: self.fail ('Expected an EOF exception.') + def test_buffer_interface(self): + p = pexpect.spawn('cat', timeout=5) + p.sendline (b'Hello') + p.expect (b'Hello') + assert len(p.buffer) + p.buffer = b'Testing' + p.sendeof () + def _before_after(self, p): p.timeout = 5 diff --git a/tests/test_performance.py b/tests/test_performance.py index 7be0cf6..63778af 100755 --- a/tests/test_performance.py +++ b/tests/test_performance.py @@ -23,6 +23,7 @@ from __future__ import print_function import unittest, time, sys import platform import pexpect +import re from . import PexpectTestCase # This isn't exactly a unit test, but it fits in nicely with the rest of the tests. @@ -101,6 +102,11 @@ class PerformanceTestCase (PexpectTestCase.PexpectTestCase): self.faster_range(100000) print("100000 calls to faster_range:", (time.time() - start_time)) + def test_large_stdout_stream(self): + e = pexpect.spawn('openssl rand -base64 {}'.format(1024*1024*25), searchwindowsize=1000) + resp = e.expect(['Password:', pexpect.EOF, pexpect.TIMEOUT]) + assert resp == 1 # index 1 == EOF + if __name__ == "__main__": unittest.main() |