Commit c3fb1211 authored by Jason Madden's avatar Jason Madden

test__fileobject: Make readinto test use readable names; make readinto test...

test__fileobject: Make readinto test use readable names; make readinto test not leak file descriptors; add change note for #1948.

Fixes #1948
parent bc406517
Make gevent's ``FileObjectThread`` (mostly used on Windows) implement
``readinto`` cooperatively. PR by Kirill Smelkov.
...@@ -305,14 +305,15 @@ class TestFileObjectBlock(CleanupMixin, ...@@ -305,14 +305,15 @@ class TestFileObjectBlock(CleanupMixin,
os.write(fileno, b'hello world') os.write(fileno, b'hello world')
os.close(fileno) os.close(fileno)
with self._makeOne(path, 'rb') as f:
buf = bytearray(32) buf = bytearray(32)
mbuf = memoryview(buf) mbuf = memoryview(buf)
def assertReadInto(n, dataok):
n_ = f.readinto(mbuf[:n])
self.assertEqual(n_, len(dataok))
self.assertEqual(buf[:n_], dataok)
def assertReadInto(byte_count, expected_data):
bytes_read = f.readinto(mbuf[:byte_count])
self.assertEqual(bytes_read, len(expected_data))
self.assertEqual(buf[:bytes_read], expected_data)
with self._makeOne(path, 'rb') as f:
assertReadInto(2, b'he') assertReadInto(2, b'he')
assertReadInto(1, b'l') assertReadInto(1, b'l')
assertReadInto(32, b'lo world') assertReadInto(32, b'lo world')
...@@ -392,8 +393,8 @@ class ConcurrentFileObjectMixin(object): ...@@ -392,8 +393,8 @@ class ConcurrentFileObjectMixin(object):
# if .readinto() is not cooperative spawned greenlet will not be able # if .readinto() is not cooperative spawned greenlet will not be able
# to run and call to .readinto() will block forever. # to run and call to .readinto() will block forever.
r, w = self._pipe() r, w = self._pipe()
rf = self._makeOne(r, 'rb') rf = self._close_on_teardown(self._makeOne(r, 'rb'))
wf = self._makeOne(w, 'wb') wf = self._close_on_teardown(self._makeOne(w, 'wb'))
g = gevent.spawn(Writer, wf, [b'hello']) g = gevent.spawn(Writer, wf, [b'hello'])
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment