diff options
author | Thomas Kluyver <takowl@gmail.com> | 2014-02-07 09:50:57 -0800 |
---|---|---|
committer | Thomas Kluyver <takowl@gmail.com> | 2014-02-07 09:50:57 -0800 |
commit | a97f580d5cdd0f479ea64d36edc164ea769d4084 (patch) | |
tree | 7f6eea4e5e1385b9e255e9987a3c90282958abf4 | |
parent | 1972ab52a651de11246cc2aeaee654dc0f3a8437 (diff) | |
parent | 9b74f12bbe35f2a60b5cc389438fefd0218fec40 (diff) | |
download | pexpect-a97f580d5cdd0f479ea64d36edc164ea769d4084.tar.gz |
Merge pull request #38 from mattprintz/master
Bug: AttributeError: 'error' object has no attribute 'errno'
-rw-r--r-- | pexpect/__init__.py | 2 | ||||
-rwxr-xr-x | tests/sleep_for.py | 41 | ||||
-rwxr-xr-x | tests/test_expect.py | 21 |
3 files changed, 63 insertions, 1 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py index a6fb875..c0ad145 100644 --- a/pexpect/__init__.py +++ b/pexpect/__init__.py @@ -1687,7 +1687,7 @@ class spawn(object): return select.select(iwtd, owtd, ewtd, timeout) except select.error: err = sys.exc_info()[1] - if err.errno == errno.EINTR: + if err.args[0] == errno.EINTR: # if we loop back we have to subtract the # amount of time we already waited. if timeout is not None: diff --git a/tests/sleep_for.py b/tests/sleep_for.py new file mode 100755 index 0000000..9027105 --- /dev/null +++ b/tests/sleep_for.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <noah@noah.org> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' + +from __future__ import print_function + +import time +import sys + +def main(): + """ + This script sleeps for the number of seconds (float) specified by the + command line argument. + """ + if len(sys.argv) < 2: + print("Usage: %s seconds_to_sleep" % (sys.argv[0],)) + sys.exit(1) + timeout = float(sys.argv[1]) + print("READY") + time.sleep(timeout) + print("END") + +if __name__ == '__main__': + main() diff --git a/tests/test_expect.py b/tests/test_expect.py index ba54cb5..d5d0c9c 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -25,6 +25,7 @@ import subprocess import time import PexpectTestCase import sys +import signal #import pdb # Many of these test cases blindly assume that sequential directory @@ -490,6 +491,26 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): p.expect_exact('def') p.expect(pexpect.EOF) + def test_signal_handling(self): + ''' + This tests the error handling of a signal interrupt (usually a + SIGWINCH generated when a window is resized), but in this test, we + are substituting an ALARM signal as this is much easier for testing + and is treated the same as a SIGWINCH. + + To ensure that the alarm fires during the expect call, we are + setting the signal to alarm after 1 second while the spawned process + sleeps for 2 seconds prior to sending the expected output. + ''' + def noop(x, y): + pass + signal.signal(signal.SIGALRM, noop) + + p1 = pexpect.spawn('%s sleep_for.py 2' % self.PYTHONBIN) + p1.expect('READY', timeout=10) + signal.alarm(1) + p1.expect('END', timeout=10) + if __name__ == '__main__': unittest.main() |