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

Function test_memory_map_writer

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

Source from the content-addressed store, hash-verified

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