Skip to content

bpo-32604: Clean up test.support.interpreters. #20926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Clean up test.test_interpreters.TestSendRecv.
  • Loading branch information
ericsnowcurrently committed Jun 16, 2020
commit 153222a0ebe768dfced78b29be3c5d5f505c5c00
2 changes: 1 addition & 1 deletion Lib/test/support/interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run(self, src_str, /, *, channels=None):
Run the given source code in the interpreter.
This blocks the current Python thread until done.
"""
_interpreters.run_string(self._id, src_str)
_interpreters.run_string(self._id, src_str, channels)


def create_channel():
Expand Down
48 changes: 23 additions & 25 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def clean_up_interpreters():
pass # already destroyed


def _run_output(interp, request, shared=None):
def _run_output(interp, request, channels=None):
script, rpipe = _captured_script(request)
with rpipe:
interp.run(script)
interp.run(script, channels=channels)
return rpipe.read()


Expand Down Expand Up @@ -464,22 +464,22 @@ class TestSendRecv(TestBase):
def test_send_recv_main(self):
r, s = interpreters.create_channel()
orig = b'spam'
s.send(orig)
s.send_nowait(orig)
obj = r.recv()

self.assertEqual(obj, orig)
self.assertIsNot(obj, orig)

def test_send_recv_same_interpreter(self):
interp = interpreters.create()
out = _run_output(interp, dedent("""
interp.run(dedent("""
from test.support import interpreters
r, s = interpreters.create_channel()
orig = b'spam'
s.send(orig)
s.send_nowait(orig)
obj = r.recv()
assert obj is not orig
assert obj == orig
assert obj == orig, 'expected: obj == orig'
assert obj is not orig, 'expected: obj is not orig'
"""))

def test_send_recv_different_threads(self):
Expand All @@ -496,40 +496,38 @@ def f():
t = threading.Thread(target=f)
t.start()

s.send(b'spam')
orig = b'spam'
s.send(orig)
t.join()
obj = r.recv()

self.assertEqual(obj, b'spam')
self.assertEqual(obj, orig)
self.assertIsNot(obj, orig)

def test_send_recv_nowait_main(self):
r, s = interpreters.create_channel()
orig = b'spam'
s.send(orig)
s.send_nowait(orig)
obj = r.recv_nowait()

self.assertEqual(obj, orig)
self.assertIsNot(obj, orig)

def test_send_recv_nowait_main_with_default(self):
r, _ = interpreters.create_channel()
obj = r.recv_nowait(None)

self.assertIsNone(obj)

def test_send_recv_nowait_same_interpreter(self):
interp = interpreters.create()
out = _run_output(interp, dedent("""
interp.run(dedent("""
from test.support import interpreters
r, s = interpreters.create_channel()
orig = b'spam'
s.send(orig)
s.send_nowait(orig)
obj = r.recv_nowait()
assert obj is not orig
assert obj == orig
assert obj == orig, 'expected: obj == orig'
# When going back to the same interpreter we get the same object.
assert obj is not orig, 'expected: obj is not orig'
"""))

r, s = interpreters.create_channel()

def f():
while True:
try:
obj = r.recv_nowait()
break
except _interpreters.ChannelEmptyError:
time.sleep(0.1)
s.send(obj)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy