diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2014-02-16 16:57:23 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2014-02-16 16:57:23 -0700 |
commit | 25ac48f98e5a12d653963a2da4607ba5cac3bffa (patch) | |
tree | ec95ac4410a693e3442c37ed355655de80cac606 | |
parent | 2a8eea93f8fa8294448224e84276358ab2cd3b23 (diff) | |
parent | 5669280ac3535c3fed083fcb1fedef2064d227fd (diff) | |
download | numpy-25ac48f98e5a12d653963a2da4607ba5cac3bffa.tar.gz |
Merge pull request #4299 from juliantaylor/win-tempfile-fix
Windows tempfile fix
-rw-r--r-- | doc/f2py/f2py.1 | 2 | ||||
-rw-r--r-- | doc/source/f2py/usage.rst | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_memmap.py | 35 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 7 |
4 files changed, 25 insertions, 21 deletions
diff --git a/doc/f2py/f2py.1 b/doc/f2py/f2py.1 index 279647424..7f51ea29d 100644 --- a/doc/f2py/f2py.1 +++ b/doc/f2py/f2py.1 @@ -53,7 +53,7 @@ Do [not] lower the cases in <fortran files>. By default, \-\-lower is assumed with \-h key, and \-\-no\-lower without \-h key. .TP .B \-\-build\-dir <dirname> -All f2py generated files are created in <dirname>. Default is tempfile.mktemp(). +All f2py generated files are created in <dirname>. Default is tempfile.mkdtemp(). .TP .B \-\-overwrite\-signature Overwrite existing signature file. diff --git a/doc/source/f2py/usage.rst b/doc/source/f2py/usage.rst index 2f9017faa..a6f093154 100644 --- a/doc/source/f2py/usage.rst +++ b/doc/source/f2py/usage.rst @@ -183,7 +183,7 @@ Other options: without the ``-h`` switch. ``--build-dir <dirname>`` All F2PY generated files are created in ``<dirname>``. Default is - ``tempfile.mktemp()``. + ``tempfile.mkdtemp()``. ``--quiet`` Run quietly. ``--verbose`` diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index 10e7a0817..b364f5eb9 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -1,8 +1,9 @@ from __future__ import division, absolute_import, print_function import sys -from tempfile import NamedTemporaryFile, TemporaryFile +from tempfile import NamedTemporaryFile, TemporaryFile, mktemp, mkdtemp import os +import shutil from numpy import memmap from numpy import arange, allclose, asarray @@ -11,6 +12,7 @@ from numpy.testing import * class TestMemmap(TestCase): def setUp(self): self.tmpfp = NamedTemporaryFile(prefix='mmap') + self.tempdir = mkdtemp() self.shape = (3, 4) self.dtype = 'float32' self.data = arange(12, dtype=self.dtype) @@ -18,6 +20,7 @@ class TestMemmap(TestCase): def tearDown(self): self.tmpfp.close() + shutil.rmtree(self.tempdir) def test_roundtrip(self): # Write data to file @@ -33,11 +36,11 @@ class TestMemmap(TestCase): assert_array_equal(self.data, newfp) def test_open_with_filename(self): - with NamedTemporaryFile() as tmp: - fp = memmap(tmp.name, dtype=self.dtype, mode='w+', - shape=self.shape) - fp[:] = self.data[:] - del fp + tmpname = mktemp('', 'mmap', dir=self.tempdir) + fp = memmap(tmpname, dtype=self.dtype, mode='w+', + shape=self.shape) + fp[:] = self.data[:] + del fp def test_unnamed_file(self): with TemporaryFile() as f: @@ -54,16 +57,16 @@ class TestMemmap(TestCase): del fp def test_filename(self): - with NamedTemporaryFile() as tmp: - fp = memmap(tmp.name, dtype=self.dtype, mode='w+', - shape=self.shape) - abspath = os.path.abspath(tmp.name) - fp[:] = self.data[:] - self.assertEqual(abspath, fp.filename) - b = fp[:1] - self.assertEqual(abspath, b.filename) - del b - del fp + tmpname = mktemp('', 'mmap', dir=self.tempdir) + fp = memmap(tmpname, dtype=self.dtype, mode='w+', + shape=self.shape) + abspath = os.path.abspath(tmpname) + fp[:] = self.data[:] + self.assertEqual(abspath, fp.filename) + b = fp[:1] + self.assertEqual(abspath, b.filename) + del b + del fp def test_filename_fileobj(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode="w+", diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 40e508549..a73b3350d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function import tempfile import sys import os +import shutil import warnings import operator import io @@ -2373,11 +2374,11 @@ class TestIO(object): self.x = rand(shape) + rand(shape).astype(np.complex)*1j self.x[0,:, 1] = [nan, inf, -inf, nan] self.dtype = self.x.dtype - self.file = tempfile.NamedTemporaryFile() - self.filename = self.file.name + self.tempdir = tempfile.mkdtemp() + self.filename = tempfile.mktemp(dir=self.tempdir) def tearDown(self): - self.file.close() + shutil.rmtree(self.tempdir) def test_bool_fromstring(self): v = np.array([True, False, True, False], dtype=np.bool_) |