summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjquast <contact@jeffquast.com>2014-08-24 15:06:15 -0700
committerjquast <contact@jeffquast.com>2014-08-24 15:06:15 -0700
commite2ff2f47fc7719ebf4375eec81f996362816bb10 (patch)
treeb8cdf2ee0ebf80d2a977c785eaefb085a5335cf2 /tests
parent8d96042177a6986ae5b117e31916638309b2fd03 (diff)
downloadpexpect-e2ff2f47fc7719ebf4375eec81f996362816bb10.tar.gz
Closes issue #86 and issue #100
Fallback to using stdout, and, when both stdin and stdout are *both* closed, catch ValueError and use the same constants as when the attached process is not a terminal.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_expect.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/test_expect.py b/tests/test_expect.py
index 8ccb9c5..3f4c9d8 100755
--- a/tests/test_expect.py
+++ b/tests/test_expect.py
@@ -18,11 +18,13 @@ PEXPECT LICENSE
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
+import multiprocessing
import unittest
import subprocess
import time
import signal
import sys
+import os
import pexpect
from . import PexpectTestCase
@@ -542,7 +544,40 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase):
signal.alarm(1)
p1.expect('END')
+ def test_stdin_closed(self):
+ '''
+ Ensure pexpect continues to operate even when stdin is closed
+ '''
+ class Closed_stdin_proc(multiprocessing.Process):
+ def run(self):
+ sys.__stdin__.close()
+ cat = pexpect.spawn('cat')
+ cat.sendeof()
+ cat.expect(pexpect.EOF)
+
+ proc = Closed_stdin_proc()
+ proc.start()
+ proc.join()
+ assert proc.exitcode == 0
+
+ def test_stdin_stdout_closed(self):
+ '''
+ Ensure pexpect continues to operate even when stdin and stdout is closed
+ '''
+ class Closed_stdin_stdout_proc(multiprocessing.Process):
+ def run(self):
+ sys.__stdin__.close()
+ sys.__stdout__.close()
+ cat = pexpect.spawn('cat')
+ cat.sendeof()
+ cat.expect(pexpect.EOF)
+
+ proc = Closed_stdin_stdout_proc()
+ proc.start()
+ proc.join()
+ assert proc.exitcode == 0
+
if __name__ == '__main__':
unittest.main()
-suite = unittest.makeSuite(ExpectTestCase,'test')
+suite = unittest.makeSuite(ExpectTestCase, 'test')