mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-76785: Add SendChannel.send_buffer() (#110246)
(This is still a test module.)
This commit is contained in:
parent
f4cb0d27cc
commit
7bd560ce8d
13 changed files with 467 additions and 67 deletions
|
@ -1067,3 +1067,46 @@ class TestSendRecv(TestBase):
|
|||
self.assertEqual(obj4, b'spam')
|
||||
self.assertEqual(obj5, b'eggs')
|
||||
self.assertIs(obj6, default)
|
||||
|
||||
def test_send_buffer(self):
|
||||
buf = bytearray(b'spamspamspam')
|
||||
obj = None
|
||||
rch, sch = interpreters.create_channel()
|
||||
|
||||
def f():
|
||||
nonlocal obj
|
||||
while True:
|
||||
try:
|
||||
obj = rch.recv()
|
||||
break
|
||||
except interpreters.ChannelEmptyError:
|
||||
time.sleep(0.1)
|
||||
t = threading.Thread(target=f)
|
||||
t.start()
|
||||
|
||||
sch.send_buffer(buf)
|
||||
t.join()
|
||||
|
||||
self.assertIsNot(obj, buf)
|
||||
self.assertIsInstance(obj, memoryview)
|
||||
self.assertEqual(obj, buf)
|
||||
|
||||
buf[4:8] = b'eggs'
|
||||
self.assertEqual(obj, buf)
|
||||
obj[4:8] = b'ham.'
|
||||
self.assertEqual(obj, buf)
|
||||
|
||||
def test_send_buffer_nowait(self):
|
||||
buf = bytearray(b'spamspamspam')
|
||||
rch, sch = interpreters.create_channel()
|
||||
sch.send_buffer_nowait(buf)
|
||||
obj = rch.recv()
|
||||
|
||||
self.assertIsNot(obj, buf)
|
||||
self.assertIsInstance(obj, memoryview)
|
||||
self.assertEqual(obj, buf)
|
||||
|
||||
buf[4:8] = b'eggs'
|
||||
self.assertEqual(obj, buf)
|
||||
obj[4:8] = b'ham.'
|
||||
self.assertEqual(obj, buf)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue