MCPcopy Index your code
hub / github.com/python/cpython / test_communicate_timeout

Method test_communicate_timeout

Lib/test/test_subprocess.py:1002–1019  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1000 self.assertIsNone(stderr)
1001
1002 def test_communicate_timeout(self):
1003 p = subprocess.Popen([sys.executable, "-c",
1004 'import sys,os,time;'
1005 'sys.stderr.write("pineapple\\n");'
1006 'time.sleep(1);'
1007 'sys.stderr.write("pear\\n");'
1008 'sys.stdout.write(sys.stdin.read())'],
1009 universal_newlines=True,
1010 stdin=subprocess.PIPE,
1011 stdout=subprocess.PIPE,
1012 stderr=subprocess.PIPE)
1013 self.assertRaises(subprocess.TimeoutExpired, p.communicate, "banana",
1014 timeout=0.3)
1015 # Make sure we can keep waiting for it, and that we get the whole output
1016 # after it completes.
1017 (stdout, stderr) = p.communicate()
1018 self.assertEqual(stdout, "banana")
1019 self.assertEqual(stderr.encode(), b"pineapple\npear\n")
1020
1021 def test_communicate_timeout_large_output(self):
1022 # Test an expiring timeout while the child is outputting lots of data.

Callers

nothing calls this directly

Calls 4

communicateMethod · 0.95
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected