diff options
-rw-r--r-- | tests/alarm_die.py | 5 | ||||
-rwxr-xr-x | tests/test_isalive.py | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/alarm_die.py b/tests/alarm_die.py new file mode 100644 index 0000000..a1519ab --- /dev/null +++ b/tests/alarm_die.py @@ -0,0 +1,5 @@ +import signal, time + +signal.alarm(1) # Schedule SIGALRM in 1s + +time.sleep(6)
\ No newline at end of file diff --git a/tests/test_isalive.py b/tests/test_isalive.py index 7f02b9e..7810e2e 100755 --- a/tests/test_isalive.py +++ b/tests/test_isalive.py @@ -18,9 +18,9 @@ PEXPECT LICENSE OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ''' -from __future__ import with_statement # bring 'with' stmt to py25 import pexpect import unittest +import signal import sys, os, time import PexpectTestCase @@ -48,6 +48,15 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase): else: self.fail ('Should have raised ExceptionPython because you can\'t call wait on a dead process.') + def test_signal_wait(self): + '''Test calling wait with a process terminated by a signal.''' + if not hasattr(signal, 'SIGALRM'): + return 'SKIP' + p = pexpect.spawn(sys.executable, ['alarm_die.py']) + p.wait() + assert p.exitstatus is None, p.exitstatus + self.assertEqual(p.signalstatus, signal.SIGALRM) + def test_expect_isalive_dead_after_normal_termination (self): p = pexpect.spawn('ls') p.expect(pexpect.EOF) |