Skip to content

Commit 5f3d04f

Browse files
authored
Improve the subprocess restore_signals=True test. (GH-7414)
It wasn't testing functionality. Now it is (on Linux anyways).
1 parent c56b17b commit 5f3d04f

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Lib/test/test_subprocess.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,13 +1617,29 @@ def bad_error(*args):
16171617

16181618
self.assertIn(repr(error_data), str(e.exception))
16191619

1620-
1620+
@unittest.skipIf(not os.path.exists('/proc/self/status'),
1621+
"need /proc/self/status")
16211622
def test_restore_signals(self):
1622-
# Code coverage for both values of restore_signals to make sure it
1623-
# at least does not blow up.
1624-
# A test for behavior would be complex. Contributions welcome.
1625-
subprocess.call([sys.executable, "-c", ""], restore_signals=True)
1626-
subprocess.call([sys.executable, "-c", ""], restore_signals=False)
1623+
# Blindly assume that cat exists on systems with /proc/self/status...
1624+
default_proc_status = subprocess.check_output(
1625+
['cat', '/proc/self/status'],
1626+
restore_signals=False)
1627+
for line in default_proc_status.splitlines():
1628+
if line.startswith(b'SigIgn'):
1629+
default_sig_ign_mask = line
1630+
break
1631+
else:
1632+
self.skipTest("SigIgn not found in /proc/self/status.")
1633+
restored_proc_status = subprocess.check_output(
1634+
['cat', '/proc/self/status'],
1635+
restore_signals=True)
1636+
for line in restored_proc_status.splitlines():
1637+
if line.startswith(b'SigIgn'):
1638+
restored_sig_ign_mask = line
1639+
break
1640+
self.assertNotEqual(default_sig_ign_mask, restored_sig_ign_mask,
1641+
msg="restore_signals=True should've unblocked "
1642+
"SIGPIPE and friends.")
16271643

16281644
def test_start_new_session(self):
16291645
# For code coverage of calling setsid(). We don't care if we get an

0 commit comments

Comments
 (0)