From 5b2ec06a57f102357e86ee1320ac2d179dba3052 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 15 May 2020 18:32:37 -0600 Subject: [PATCH] Fix tests (due to same-interpreter shortcut). --- Lib/test/test__xxsubinterpreters.py | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py index 6998e9797c2..8a8d3f67410 100644 --- a/Lib/test/test__xxsubinterpreters.py +++ b/Lib/test/test__xxsubinterpreters.py @@ -1398,7 +1398,8 @@ class ChannelTests(TestBase): obj = interpreters.channel_recv(cid) self.assertEqual(obj, orig) - self.assertIsNot(obj, orig) + # When going back to the same interpreter we get the same object. + self.assertIs(obj, orig) def test_send_recv_same_interpreter(self): id1 = interpreters.create() @@ -1408,8 +1409,9 @@ class ChannelTests(TestBase): orig = b'spam' _interpreters.channel_send(cid, orig) obj = _interpreters.channel_recv(cid) - assert obj is not orig assert obj == orig + # When going back to the same interpreter we get the same object. + assert obj is orig """)) def test_send_recv_different_interpreters(self): @@ -1423,6 +1425,37 @@ class ChannelTests(TestBase): self.assertEqual(obj, b'spam') + def test_send_recv_round_trip_same_channel(self): + cid = interpreters.channel_create() + id1 = interpreters.create() + orig = b'spam' + interpreters.channel_send(cid, orig) + out = _run_output(id1, dedent(f""" + import _xxsubinterpreters as _interpreters + obj = _interpreters.channel_recv({cid}) + _interpreters.channel_send({cid}, obj) + """)) + obj = interpreters.channel_recv(cid) + + self.assertEqual(obj, orig) + self.assertIsNot(obj, orig) + + def test_send_recv_round_trip_different_channel(self): + cid1 = interpreters.channel_create() + cid2 = interpreters.channel_create() + id1 = interpreters.create() + orig = b'spam' + interpreters.channel_send(cid1, orig) + out = _run_output(id1, dedent(f""" + import _xxsubinterpreters as _interpreters + obj = _interpreters.channel_recv({cid1}) + _interpreters.channel_send({cid2}, obj) + """)) + obj = interpreters.channel_recv(cid2) + + self.assertEqual(obj, orig) + self.assertIsNot(obj, orig) + def test_send_recv_different_threads(self): cid = interpreters.channel_create()