diff options
author | David Cournapeau <cournape@gmail.com> | 2008-12-27 11:46:08 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-12-27 11:46:08 +0000 |
commit | 9c869d6547d8e637b005473bc26e2cf305a4bb6b (patch) | |
tree | f16fdaea6a049a3d1c5a63090b96d2e60886b388 /numpy/lib/tests/test_io.py | |
parent | 4e99df67658a4e43f68e2fa5773267583ac586ea (diff) | |
download | numpy-9c869d6547d8e637b005473bc26e2cf305a4bb6b.tar.gz |
BUG (#827): close temp file before reopning them on windows, and make sure they are not automatically deleted on close either (2.6and higher specific).
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 885fd3616..aee727efa 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3,6 +3,10 @@ import numpy as np import StringIO from tempfile import NamedTemporaryFile +import sys + + +MAJVER, MINVER = sys.version_info[:2] class RoundtripTest: def roundtrip(self, save_func, *args, **kwargs): @@ -25,7 +29,14 @@ class RoundtripTest: file_on_disk = kwargs.get('file_on_disk', False) if file_on_disk: - target_file = NamedTemporaryFile() + # Do not delete the file on windows, because we can't + # reopen an already opened file on that platform, so we + # need to close the file and reopen it, implying no + # automatic deletion. + if sys.platform == 'win32' and MAJVER >= 2 and MINVER >= 6: + target_file = NamedTemporaryFile(delete=False) + else: + target_file = NamedTemporaryFile() load_file = target_file.name else: target_file = StringIO.StringIO() @@ -37,6 +48,9 @@ class RoundtripTest: target_file.flush() target_file.seek(0) + if sys.platform == 'win32' and not isinstance(target_file, StringIO.StringIO): + target_file.close() + arr_reloaded = np.load(load_file, **load_kwds) self.arr = arr |