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

Function test_python_file_get_stream

python/pyarrow/tests/test_io.py:139–178  ·  view source on GitHub ↗
(nbytes, file_offset)

Source from the content-addressed store, hash-verified

137@pytest.mark.parametrize("nbytes", (-1, 0, 1, 5, 100))
138@pytest.mark.parametrize("file_offset", (-1, 0, 5, 100))
139def test_python_file_get_stream(nbytes, file_offset):
140
141 data = b'data1data2data3data4data5'
142
143 f = pa.PythonFile(BytesIO(data), mode='r')
144
145 # negative nbytes or offsets don't make sense here, raise ValueError
146 if nbytes < 0 or file_offset < 0:
147 with pytest.raises(pa.ArrowInvalid,
148 match="should be a positive value"):
149 f.get_stream(file_offset=file_offset, nbytes=nbytes)
150 f.close()
151 return
152 else:
153 stream = f.get_stream(file_offset=file_offset, nbytes=nbytes)
154
155 # Subsequent calls to 'read' should match behavior if same
156 # data passed to BytesIO where get_stream should handle if
157 # nbytes/file_offset results in no bytes b/c out of bounds.
158 start = min(file_offset, len(data))
159 end = min(file_offset + nbytes, len(data))
160 buf = BytesIO(data[start:end])
161
162 # read some chunks
163 assert stream.read(nbytes=4) == buf.read(4)
164 assert stream.read(nbytes=6) == buf.read(6)
165
166 # Read to end of each stream
167 assert stream.read() == buf.read()
168
169 # Try reading past the stream
170 n = len(data) * 2
171 assert stream.read(n) == buf.read(n)
172
173 # NativeFile[CInputStream] is not seekable
174 with pytest.raises(OSError, match="seekable"):
175 stream.seek(0)
176
177 stream.close()
178 assert stream.closed
179
180
181def test_python_file_read_at():

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
PythonFileMethod · 0.80
seekMethod · 0.80
closeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected