diff options
author | Pauli Virtanen <pav@iki.fi> | 2009-03-30 19:06:31 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2009-03-30 19:06:31 +0000 |
commit | cdf6562c5552369e363d9811bf45f5ab15f0ff80 (patch) | |
tree | f51f232eb83374d0fd20fbc0f4c4fbc39fb0adf7 /numpy/lib/tests/test_io.py | |
parent | 3073f2c5afe8260bf62d5056fd22ef8686465663 (diff) | |
download | numpy-cdf6562c5552369e363d9811bf45f5ab15f0ff80.tar.gz |
Fixed #852: avoid filename clashes in savez, by using a secure temporary file name
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index adc434235..469c1e002 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -5,6 +5,7 @@ from numpy.ma.testutils import * import StringIO import gzip import os +import threading from tempfile import mkstemp, NamedTemporaryFile import sys, time @@ -120,6 +121,32 @@ class TestSavezLoad(RoundtripTest, TestCase): assert_equal(a, l['file_a']) assert_equal(b, l['file_b']) + def test_savez_filename_clashes(self): + # Test that issue #852 is fixed + # and savez functions in multithreaded environment + + def writer(error_list): + fd, tmp = mkstemp(suffix='.npz') + os.close(fd) + try: + arr = np.random.randn(500,500) + try: + np.savez(tmp, arr=arr) + except OSError, err: + error_list.append(err) + finally: + os.remove(tmp) + + errors = [] + threads = [threading.Thread(target=writer, args=(errors,)) + for j in xrange(3)] + for t in threads: + t.start() + for t in threads: + t.join() + + if errors: + raise AssertionError(errors) class TestSaveTxt(TestCase): def test_array(self): |