Skip to content

Commit 8e59617

Browse files
committed
Use pytest tmpdir for large memory map fixture so works on Windows
Change-Id: Ia2d359a11fcecb9ce68af03554010acfc38de091
1 parent 8a42f30 commit 8e59617

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

python/pyarrow/tests/test_serialization.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from __future__ import absolute_import
1918
from __future__ import division
20-
from __future__ import print_function
19+
20+
import pytest
2121

2222
from collections import namedtuple
2323
import os
@@ -202,27 +202,34 @@ def serialization_roundtrip(value, f):
202202
result = pa.lib.deserialize_sequence(f, None)
203203
assert_equal(value, result)
204204

205-
# Create a large memory mapped file
206-
SIZE = 100 * 1024 * 1024 # 100 MB
207-
arr = np.random.randint(0, 256, size=SIZE).astype('u1')
208-
data = arr.tobytes()[:SIZE]
209-
path = os.path.join("/tmp/pyarrow-temp-file")
210-
with open(path, 'wb') as f:
211-
f.write(data)
212205

213-
MEMORY_MAPPED_FILE = pa.memory_map(path, mode="r+")
206+
@pytest.yield_fixture(scope='session')
207+
def large_memory_map(tmpdir_factory):
208+
path = (tmpdir_factory.mktemp('data')
209+
.join('pyarrow-serialization-tmp-file').strpath)
210+
211+
# Create a large memory mapped file
212+
SIZE = 100 * 1024 * 1024 # 100 MB
213+
with open(path, 'wb') as f:
214+
f.write(np.random.randint(0, 256, size=SIZE)
215+
.astype('u1')
216+
.tobytes()
217+
[:SIZE])
218+
219+
yield pa.memory_map(path, mode="r+")
220+
os.remove(path)
214221

215222

216-
def test_primitive_serialization():
223+
def test_primitive_serialization(large_memory_map):
217224
for obj in PRIMITIVE_OBJECTS:
218-
serialization_roundtrip([obj], MEMORY_MAPPED_FILE)
225+
serialization_roundtrip([obj], large_memory_map)
219226

220227

221-
def test_complex_serialization():
228+
def test_complex_serialization(large_memory_map):
222229
for obj in COMPLEX_OBJECTS:
223-
serialization_roundtrip([obj], MEMORY_MAPPED_FILE)
230+
serialization_roundtrip([obj], large_memory_map)
224231

225232

226-
def test_custom_serialization():
233+
def test_custom_serialization(large_memory_map):
227234
for obj in CUSTOM_OBJECTS:
228-
serialization_roundtrip([obj], MEMORY_MAPPED_FILE)
235+
serialization_roundtrip([obj], large_memory_map)

0 commit comments

Comments
 (0)