summaryrefslogtreecommitdiff
path: root/tests/test_misc.py
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2014-11-23 20:14:16 -0800
committerJeff Quast <contact@jeffquast.com>2014-11-23 20:14:16 -0800
commita75faec32169c11f95fd5363e9711f52fba99117 (patch)
treeabc8c96fa467f97867333807ac1ac70daebb21ae /tests/test_misc.py
parent526dc9cafcc922dbccbd8f1936eb400df8a8c7c5 (diff)
downloadpexpect-a75faec32169c11f95fd5363e9711f52fba99117.tar.gz
Set default signal handlers for SIGINT and SIGHUP.
According to test_misc.py comments, fedora's build agent has the same problem as ours. We use the setUp and tearDown methods to set and restore these signals, if ignored.
Diffstat (limited to 'tests/test_misc.py')
-rwxr-xr-xtests/test_misc.py51
1 files changed, 17 insertions, 34 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 9e44bab..28df570 100755
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -149,41 +149,24 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase):
def test_sighup(self):
" validate argument `ignore_sighup=True` and `ignore_sighup=False`. "
- # If a parent process sets an Ignore handler for SIGHUP (as on Fedora's
- # build machines), this test breaks. We temporarily restore the default
- # handler, so the child process will quit. However, we can't simply
- # replace any installed handler, because getsignal returns None for
- # handlers not set in Python code, so we wouldn't be able to restore
- # them.
- if signal.getsignal(signal.SIGHUP) == signal.SIG_IGN:
- signal.signal(signal.SIGHUP, signal.SIG_DFL)
- restore_sig_ign = True
- else:
- restore_sig_ign = False
-
getch = sys.executable + ' getch.py'
- try:
- child = pexpect.spawn(getch, ignore_sighup=True)
- child.expect('READY')
- child.kill(signal.SIGHUP)
- for _ in range(10):
- if not child.isalive():
- self.fail('Child process should not have exited.')
- time.sleep(0.1)
-
- child = pexpect.spawn(getch, ignore_sighup=False)
- child.expect('READY')
- child.kill(signal.SIGHUP)
- for _ in range(10):
- if not child.isalive():
- break
- time.sleep(0.1)
- else:
- self.fail('Child process should have exited.')
-
- finally:
- if restore_sig_ign:
- signal.signal(signal.SIGHUP, signal.SIG_IGN)
+ child = pexpect.spawn(getch, ignore_sighup=True)
+ child.expect('READY')
+ child.kill(signal.SIGHUP)
+ for _ in range(10):
+ if not child.isalive():
+ self.fail('Child process should not have exited.')
+ time.sleep(0.1)
+
+ child = pexpect.spawn(getch, ignore_sighup=False)
+ child.expect('READY')
+ child.kill(signal.SIGHUP)
+ for _ in range(10):
+ if not child.isalive():
+ break
+ time.sleep(0.1)
+ else:
+ self.fail('Child process should have exited.')
def test_bad_child_pid(self):
" assert bad condition error in isalive(). "