From cef1e369454845b14c65a1712b65a4708cf62c1a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 28 Sep 2017 16:26:32 +0200 Subject: [PATCH 1/2] bpo-31158: Fix test_pty.test_basic() Sometimes, the first read only returns the first written 5 bytes and a second read is need to get the second part. --- Lib/test/test_pty.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index f283e1930b7ebc4..0cf1136e2911b15 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -101,8 +101,17 @@ def test_basic(self): debug("Writing chunked output") os.write(slave_fd, TEST_STRING_2[:5]) os.write(slave_fd, TEST_STRING_2[5:]) + + expected = b'For my pet fish, Eric.\n' s2 = os.read(master_fd, 1024) - self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2)) + # bpo-31158: Sometimes, the first read only returns the first + # written 5 bytes and a second read is need to get the second part. + while len(s2) < len(expected): + chunk = os.read(master_fd, 1024) + if not chunk: + break + s2 += chunk + self.assertEqual(expected, normalize_output(s2)) os.close(slave_fd) os.close(master_fd) From 3e6a106080e1ee62187a3295e299837c09e6f369 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 28 Sep 2017 17:01:03 +0200 Subject: [PATCH 2/2] reuse TEST_STRING_2 constant --- Lib/test/test_pty.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 0cf1136e2911b15..23701b2f1a4988f 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -102,16 +102,15 @@ def test_basic(self): os.write(slave_fd, TEST_STRING_2[:5]) os.write(slave_fd, TEST_STRING_2[5:]) - expected = b'For my pet fish, Eric.\n' s2 = os.read(master_fd, 1024) # bpo-31158: Sometimes, the first read only returns the first # written 5 bytes and a second read is need to get the second part. - while len(s2) < len(expected): + while len(s2) < len(TEST_STRING_2): chunk = os.read(master_fd, 1024) if not chunk: break s2 += chunk - self.assertEqual(expected, normalize_output(s2)) + self.assertEqual(TEST_STRING_2, normalize_output(s2)) os.close(slave_fd) os.close(master_fd)