Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: AttributeError: 'error' object has no attribute 'errno' #38

Merged
merged 4 commits into from Feb 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pexpect/__init__.py
Expand Up @@ -1687,7 +1687,7 @@ def __select(self, iwtd, owtd, ewtd, timeout=None):
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:
Expand Down
41 changes: 41 additions & 0 deletions 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()
21 changes: 21 additions & 0 deletions tests/test_expect.py
Expand Up @@ -25,6 +25,7 @@
import time
import PexpectTestCase
import sys
import signal
#import pdb

# Many of these test cases blindly assume that sequential directory
Expand Down Expand Up @@ -490,6 +491,26 @@ def test_timeout_none(self):
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()

Expand Down