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

Function test_memory_map_writer

python/pyarrow/tests/test_io.py:1160–1200  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

1158
1159
1160def test_memory_map_writer(tmpdir):
1161 if sys.platform == "emscripten":
1162 pytest.xfail("Multiple memory maps to same file don't work on emscripten")
1163 SIZE = 4096
1164 arr = [random.randint(0, 255) for _ in range(SIZE)]
1165 data = bytes(arr[:SIZE])
1166
1167 path = os.path.join(str(tmpdir), guid())
1168 with open(path, 'wb') as f:
1169 f.write(data)
1170
1171 f = pa.memory_map(path, mode='r+b')
1172
1173 f.seek(10)
1174 f.write(b'peekaboo')
1175 assert f.tell() == 18
1176
1177 f.seek(10)
1178 assert f.read(8) == b'peekaboo'
1179
1180 f2 = pa.memory_map(path, mode='r+b')
1181
1182 f2.seek(10)
1183 f2.write(b'booapeak')
1184 f2.seek(10)
1185
1186 f.seek(10)
1187 assert f.read(8) == b'booapeak'
1188
1189 # Does not truncate file
1190 f3 = pa.memory_map(path, mode='w')
1191 f3.write(b'foo')
1192
1193 with pa.memory_map(path) as f4:
1194 assert f4.size() == SIZE
1195
1196 with pytest.raises(IOError):
1197 f3.read(5)
1198
1199 f.seek(0)
1200 assert f.read(3) == b'foo'
1201
1202
1203def test_memory_map_resize(tmpdir):

Callers

nothing calls this directly

Calls 7

guidFunction · 0.90
bytesFunction · 0.85
seekMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected