summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-02-16 12:40:42 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-02-16 12:48:32 +0100
commitf7b0265655725267063ed25478aa7c2ab20b3a85 (patch)
tree1bde6110f2b6c77e89921040b761d65719cf58fc
parent2868dc4a0513f58eafc013f3ba3d84ae07113199 (diff)
downloadnumpy-f7b0265655725267063ed25478aa7c2ab20b3a85.tar.gz
TST: avoid opening files twice which doesn't work on windows
-rw-r--r--numpy/core/tests/test_memmap.py35
-rw-r--r--numpy/core/tests/test_multiarray.py7
2 files changed, 23 insertions, 19 deletions
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_)