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:219–244  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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