summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCooper Ry Lees <me@cooperlees.com>2018-03-23 19:42:30 +0000
committerCooper Ry Lees <me@cooperlees.com>2018-03-23 19:42:30 +0000
commit6db8d9b8e91a49c75bf67a95f245733d357770a8 (patch)
tree8061e74fd1d08696cf428db13b5da22cb974e315 /tests
parentb9e793a5e0de36d304a39339a8d3c900f4755157 (diff)
downloadpexpect-git-6db8d9b8e91a49c75bf67a95f245733d357770a8.tar.gz
Allow for configurable select.poll() usage
- This allows systems that can have > 1024 fds to work - Should be marginally faster - Added tests to use select.poll() - Incremented version - Happy to change this, guessed what it should be
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_misc.py25
-rw-r--r--tests/test_socket.py19
2 files changed, 40 insertions, 4 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index fcd77d3..118de2e 100755
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -52,6 +52,15 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
return 'skip'
assert child.isatty()
+ def test_isatty_poll(self):
+ " Test isatty() is True after spawning process on most platforms. "
+ child = pexpect.spawn('cat', use_poll=True)
+ if not child.isatty() and sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ assert child.isatty()
+
def test_read(self):
" Test spawn.read by calls of various size. "
child = pexpect.spawn('cat')
@@ -65,6 +74,19 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
remaining = child.read().replace(_CAT_EOF, b'')
self.assertEqual(remaining, b'abc\r\n')
+ def test_read_poll(self):
+ " Test spawn.read by calls of various size. "
+ child = pexpect.spawn('cat', use_poll=True)
+ child.sendline("abc")
+ child.sendeof()
+ self.assertEqual(child.read(0), b'')
+ self.assertEqual(child.read(1), b'a')
+ self.assertEqual(child.read(1), b'b')
+ self.assertEqual(child.read(1), b'c')
+ self.assertEqual(child.read(2), b'\r\n')
+ remaining = child.read().replace(_CAT_EOF, b'')
+ self.assertEqual(remaining, b'abc\r\n')
+
def test_readline_bin_echo(self):
" Test spawn('echo'). "
# given,
@@ -148,7 +170,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
p.sendline(b'alpha')
p.expect(b'<out>alpha')
assert p.isalive()
-
+
assert not p.isalive()
def test_terminate(self):
@@ -343,4 +365,3 @@ if __name__ == '__main__':
unittest.main()
suite = unittest.makeSuite(TestCaseMisc,'test')
-
diff --git a/tests/test_socket.py b/tests/test_socket.py
index 56d69c7..21648f4 100644
--- a/tests/test_socket.py
+++ b/tests/test_socket.py
@@ -225,7 +225,7 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase):
session.expect(pexpect.EOF)
self.assertEqual(session.before, b'')
- def test_fd_isalive (self):
+ def test_fd_isalive(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))
session = fdpexpect.fdspawn(sock.fileno(), timeout=10)
@@ -233,13 +233,28 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase):
sock.close()
assert not session.isalive(), "Should not be alive after close()"
- def test_fd_isatty (self):
+ def test_fd_isalive_poll(self):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect((self.host, self.port))
+ session = fdpexpect.fdspawn(sock.fileno(), timeout=10, use_poll=True)
+ assert session.isalive()
+ sock.close()
+ assert not session.isalive(), "Should not be alive after close()"
+
+ def test_fd_isatty(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))
session = fdpexpect.fdspawn(sock.fileno(), timeout=10)
assert not session.isatty()
session.close()
+ def test_fd_isatty_poll(self):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect((self.host, self.port))
+ session = fdpexpect.fdspawn(sock.fileno(), timeout=10, use_poll=True)
+ assert not session.isatty()
+ session.close()
+
def test_fileobj(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))