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

Function test_memory_map_writer

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

Source from the content-addressed store, hash-verified

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