Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add tests.
  • Loading branch information
ericsnowcurrently committed Oct 2, 2023
commit 873eec23c996d0d23a09d6d3109430b2e996635c
43 changes: 43 additions & 0 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,3 +1055,46 @@ def test_recv_nowait_default(self):
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)