diff options
author | Matthew Printz <matt.printz@rackspace.com> | 2014-02-06 17:49:09 -0600 |
---|---|---|
committer | Matthew Printz <matt.printz@rackspace.com> | 2014-02-06 17:49:09 -0600 |
commit | 9b74f12bbe35f2a60b5cc389438fefd0218fec40 (patch) | |
tree | 7f6eea4e5e1385b9e255e9987a3c90282958abf4 | |
parent | 954f2c743123f35c991318285ff7d63390e2bd62 (diff) | |
download | pexpect-9b74f12bbe35f2a60b5cc389438fefd0218fec40.tar.gz |
Fixing test for signal interrupt exception
-rwxr-xr-x | tests/sleep_for.py (renamed from tests/sigwinch_error.py) | 11 | ||||
-rwxr-xr-x | tests/test_expect.py | 21 | ||||
-rwxr-xr-x | tests/test_winsize.py | 15 |
3 files changed, 31 insertions, 16 deletions
diff --git a/tests/sigwinch_error.py b/tests/sleep_for.py index c2f5577..9027105 100755 --- a/tests/sigwinch_error.py +++ b/tests/sleep_for.py @@ -22,10 +22,19 @@ PEXPECT LICENSE 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(2) + time.sleep(timeout) print("END") if __name__ == '__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() diff --git a/tests/test_winsize.py b/tests/test_winsize.py index e532e51..f029ad3 100755 --- a/tests/test_winsize.py +++ b/tests/test_winsize.py @@ -22,7 +22,6 @@ import pexpect import unittest import PexpectTestCase import time -import signal class TestCaseWinsize(PexpectTestCase.PexpectTestCase): @@ -53,20 +52,6 @@ class TestCaseWinsize(PexpectTestCase.PexpectTestCase): p1.close() - def test_sinch_error (self): - ''' - This tests that the child process can set and get the windows size. - This makes use of an external script sigwinch_report.py. - ''' - def noop(x, y): - pass - signal.signal(signal.SIGALRM, noop) - - p1 = pexpect.spawn('%s sigwinch_error.py' % self.PYTHONBIN) - p1.expect('READY', timeout=10) - signal.alarm(1) - p1.expect('END', timeout=10) - # def test_parent_resize (self): # pid = os.getpid() # p1 = pexpect.spawn('%s sigwinch_report.py' % self.PYTHONBIN) |