|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -from __future__ import absolute_import |
19 | 18 | from __future__ import division |
20 | | -from __future__ import print_function |
| 19 | + |
| 20 | +import pytest |
21 | 21 |
|
22 | 22 | from collections import namedtuple |
23 | 23 | import os |
@@ -202,27 +202,34 @@ def serialization_roundtrip(value, f): |
202 | 202 | result = pa.lib.deserialize_sequence(f, None) |
203 | 203 | assert_equal(value, result) |
204 | 204 |
|
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) |
212 | 205 |
|
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) |
214 | 221 |
|
215 | 222 |
|
216 | | -def test_primitive_serialization(): |
| 223 | +def test_primitive_serialization(large_memory_map): |
217 | 224 | for obj in PRIMITIVE_OBJECTS: |
218 | | - serialization_roundtrip([obj], MEMORY_MAPPED_FILE) |
| 225 | + serialization_roundtrip([obj], large_memory_map) |
219 | 226 |
|
220 | 227 |
|
221 | | -def test_complex_serialization(): |
| 228 | +def test_complex_serialization(large_memory_map): |
222 | 229 | for obj in COMPLEX_OBJECTS: |
223 | | - serialization_roundtrip([obj], MEMORY_MAPPED_FILE) |
| 230 | + serialization_roundtrip([obj], large_memory_map) |
224 | 231 |
|
225 | 232 |
|
226 | | -def test_custom_serialization(): |
| 233 | +def test_custom_serialization(large_memory_map): |
227 | 234 | for obj in CUSTOM_OBJECTS: |
228 | | - serialization_roundtrip([obj], MEMORY_MAPPED_FILE) |
| 235 | + serialization_roundtrip([obj], large_memory_map) |
0 commit comments