MCPcopy Create free account
hub / github.com/apache/arrow / test_python_file_read_buffer

Function test_python_file_read_buffer

python/pyarrow/tests/test_io.py:220–245  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

218
219
220def test_python_file_read_buffer():
221 length = 10
222 data = b'0123456798'
223 dst_buf = bytearray(data)
224
225 class DuckReader:
226 def close(self):
227 pass
228
229 @property
230 def closed(self):
231 return False
232
233 def read_buffer(self, nbytes):
234 assert nbytes == length
235 return memoryview(dst_buf)[:nbytes]
236
237 duck_reader = DuckReader()
238 with pa.PythonFile(duck_reader, mode='r') as f:
239 buf = f.read_buffer(length)
240 assert len(buf) == length
241 assert memoryview(buf).tobytes() == dst_buf[:length]
242 # buf should point to the same memory, so modifying it
243 memoryview(buf)[0] = ord(b'x')
244 # should modify the original
245 assert dst_buf[0] == ord(b'x')
246
247
248def test_python_file_correct_abc():

Callers

nothing calls this directly

Calls 4

DuckReaderClass · 0.85
lenFunction · 0.85
PythonFileMethod · 0.80
read_bufferMethod · 0.80

Tested by

no test coverage detected