MCPcopy
hub / github.com/amoffat/sh / test_stdout_callback_kill

Method test_stdout_callback_kill

tests/sh_test.py:1727–1763  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1725 self.assertNotIn("4", stdout)
1726
1727 def test_stdout_callback_kill(self):
1728 import signal
1729
1730 py = create_tmp_test(
1731 """
1732import sys
1733import os
1734import time
1735
1736for i in range(5):
1737 print(i)
1738 time.sleep(.5)
1739"""
1740 )
1741
1742 stdout = []
1743
1744 def agg(line, stdin, process):
1745 line = line.strip()
1746 stdout.append(line)
1747 if line == "3":
1748 process.kill()
1749 return True
1750
1751 import sh
1752
1753 caught_signal = False
1754 p = python("-u", py.name, _out=agg, _bg=True)
1755 try:
1756 p.wait()
1757 except sh.SignalException_SIGKILL:
1758 caught_signal = True
1759
1760 self.assertTrue(caught_signal)
1761 self.assertEqual(p.process.exit_code, -signal.SIGKILL)
1762 self.assertNotIn("4", p)
1763 self.assertNotIn("4", stdout)
1764
1765 def test_general_signal(self):
1766 from signal import SIGINT

Callers

nothing calls this directly

Calls 2

create_tmp_testFunction · 0.85
waitMethod · 0.45

Tested by

no test coverage detected