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

Method _test_bufsize_equal_one

Lib/test/test_subprocess.py:1447–1467  ·  view source on GitHub ↗
(self, line, expected, universal_newlines)

Source from the content-addressed store, hash-verified

1445 self.assertEqual(p.wait(), 0)
1446
1447 def _test_bufsize_equal_one(self, line, expected, universal_newlines):
1448 # subprocess may deadlock with bufsize=1, see issue #21332
1449 with subprocess.Popen([sys.executable, "-c", "import sys;"
1450 "sys.stdout.write(sys.stdin.readline());"
1451 "sys.stdout.flush()"],
1452 stdin=subprocess.PIPE,
1453 stdout=subprocess.PIPE,
1454 stderr=subprocess.DEVNULL,
1455 bufsize=1,
1456 universal_newlines=universal_newlines) as p:
1457 p.stdin.write(line) # expect that it flushes the line in text mode
1458 os.close(p.stdin.fileno()) # close it without flushing the buffer
1459 read_line = p.stdout.readline()
1460 with support.SuppressCrashReport():
1461 try:
1462 p.stdin.close()
1463 except OSError:
1464 pass
1465 p.stdin = None
1466 self.assertEqual(p.returncode, 0)
1467 self.assertEqual(read_line, expected)
1468
1469 def test_bufsize_equal_one_text_mode(self):
1470 # line is flushed in text mode with bufsize=1.

Calls 5

writeMethod · 0.45
closeMethod · 0.45
filenoMethod · 0.45
readlineMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected