summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE.txt2
-rw-r--r--README.md2
-rw-r--r--doc/source/dev/development_environment.rst3
-rw-r--r--doc/source/user/building.rst4
-rw-r--r--numpy/__init__.py6
-rw-r--r--numpy/core/__init__.py6
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src8
-rw-r--r--numpy/core/tests/test_regression.py6
-rw-r--r--numpy/distutils/__init__.py6
-rw-r--r--numpy/distutils/tests/test_npy_pkg_config.py54
-rw-r--r--numpy/f2py/__init__.py6
-rw-r--r--numpy/f2py/tests/util.py32
-rw-r--r--numpy/fft/__init__.py6
-rw-r--r--numpy/lib/__init__.py6
-rw-r--r--numpy/lib/tests/test_io.py86
-rw-r--r--numpy/linalg/__init__.py6
-rw-r--r--numpy/ma/__init__.py6
-rw-r--r--numpy/ma/tests/test_core.py26
-rw-r--r--numpy/ma/tests/test_mrecords.py16
-rw-r--r--numpy/matrixlib/__init__.py6
-rw-r--r--numpy/polynomial/__init__.py6
-rw-r--r--numpy/random/__init__.py6
-rw-r--r--numpy/random/mtrand/mtrand.pyx5
-rw-r--r--numpy/random/tests/test_random.py2
-rw-r--r--numpy/testing/__init__.py2
-rw-r--r--numpy/testing/nosetester.py42
-rw-r--r--numpy/tests/test_scripts.py9
27 files changed, 158 insertions, 207 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index b4139af86..9014534ab 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2005-2015, NumPy Developers.
+Copyright (c) 2005-2016, NumPy Developers.
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/README.md b/README.md
index e63d2718e..6031279b0 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ More information can be found at the website:
* http://www.numpy.org
-After installation, tests can be run with:
+After installation, tests can be run (if ``nose`` is installed) with:
python -c 'import numpy; numpy.test()'
diff --git a/doc/source/dev/development_environment.rst b/doc/source/dev/development_environment.rst
index b09728e03..0fb5a666d 100644
--- a/doc/source/dev/development_environment.rst
+++ b/doc/source/dev/development_environment.rst
@@ -137,6 +137,9 @@ run the test suite with Python 3.4, use::
For more extensive info on running and writing tests, see
https://github.com/numpy/numpy/blob/master/doc/TESTS.rst.txt .
+*Note: do not run the tests from the root directory of your numpy git repo,
+that will result in strange test errors.*
+
Rebuilding & cleaning the workspace
-----------------------------------
diff --git a/doc/source/user/building.rst b/doc/source/user/building.rst
index c5f8fea1f..8acb2fa3b 100644
--- a/doc/source/user/building.rst
+++ b/doc/source/user/building.rst
@@ -60,8 +60,8 @@ The NumPy build system uses ``distutils`` and ``numpy.distutils``.
``setuptools`` is only used when building via ``pip`` or with ``python
setupegg.py``. Using ``virtualenv`` should work as expected.
-*Note: for build instructions to do development work on NumPy itself, see
-:ref:`development-environment`*.
+*Note: for build instructions to do development work on NumPy itself, see*
+:ref:`development-environment`.
.. _parallel-builds:
diff --git a/numpy/__init__.py b/numpy/__init__.py
index d4ef54d83..0fcd5097d 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -184,9 +184,11 @@ else:
pkgload.__doc__ = PackageLoader.__call__.__doc__
+ # We don't actually use this ourselves anymore, but I'm not 100% sure that
+ # no-one else in the world is using it (though I hope not)
from .testing import Tester
- test = Tester().test
- bench = Tester().bench
+ test = testing.nosetester._numpy_tester().test
+ bench = testing.nosetester._numpy_tester().bench
from . import core
from .core import *
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py
index 16dcbe0b1..e8719ca75 100644
--- a/numpy/core/__init__.py
+++ b/numpy/core/__init__.py
@@ -55,9 +55,9 @@ __all__ += getlimits.__all__
__all__ += shape_base.__all__
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
# Make it possible so that ufuncs can be pickled
# Here are the loading and unloading functions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 060f25098..b2ba831f4 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -2866,7 +2866,9 @@ VOID_compare(char *ip1, char *ip2, PyArrayObject *ap)
if (nip1 == NULL) {
goto finish;
}
- new->f->copyswap(nip1, ip1 + offset, swap, dummy);
+ memcpy(nip1, ip1 + offset, new->elsize);
+ if (swap)
+ new->f->copyswap(nip1, NULL, swap, dummy);
}
if (swap || !npy_is_aligned(nip2, new->alignment)) {
/* create buffer and copy */
@@ -2877,7 +2879,9 @@ VOID_compare(char *ip1, char *ip2, PyArrayObject *ap)
}
goto finish;
}
- new->f->copyswap(nip2, ip2 + offset, swap, dummy);
+ memcpy(nip2, ip2 + offset, new->elsize);
+ if (swap)
+ new->f->copyswap(nip2, NULL, swap, dummy);
}
}
res = new->f->compare(nip1, nip2, dummy);
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index ac34cfa53..a61e64d8d 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -2177,5 +2177,11 @@ class TestRegression(TestCase):
# gh-6530 / gh-6553
assert_array_equal(np.percentile(np.arange(10), []), np.array([]))
+ def test_void_compare_segfault(self):
+ # gh-6922. The following should not segfault
+ a = np.ones(3, dtype=[('object', 'O'), ('int', '<i2')])
+ a.sort()
+
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/distutils/__init__.py b/numpy/distutils/__init__.py
index 9297185ef..766439d92 100644
--- a/numpy/distutils/__init__.py
+++ b/numpy/distutils/__init__.py
@@ -18,6 +18,6 @@ except ImportError:
_INSTALLED = False
if _INSTALLED:
- from numpy.testing import Tester
- test = Tester().test
- bench = Tester().bench
+ from numpy.testing.nosetester import _numpy_tester
+ test = _numpy_tester().test
+ bench = _numpy_tester().bench
diff --git a/numpy/distutils/tests/test_npy_pkg_config.py b/numpy/distutils/tests/test_npy_pkg_config.py
index 9a7284270..bdef47167 100644
--- a/numpy/distutils/tests/test_npy_pkg_config.py
+++ b/numpy/distutils/tests/test_npy_pkg_config.py
@@ -1,10 +1,9 @@
from __future__ import division, absolute_import, print_function
import os
-from tempfile import mkstemp
from numpy.distutils.npy_pkg_config import read_config, parse_flags
-from numpy.testing import TestCase, run_module_suite
+from numpy.testing import TestCase, run_module_suite, temppath
simple = """\
[meta]
@@ -39,41 +38,30 @@ simple_variable_d = {'cflags': '-I/foo/bar/include', 'libflags': '-L/foo/bar/lib
class TestLibraryInfo(TestCase):
def test_simple(self):
- fd, filename = mkstemp('foo.ini')
- try:
- pkg = os.path.splitext(filename)[0]
- try:
- os.write(fd, simple.encode('ascii'))
- finally:
- os.close(fd)
-
+ with temppath('foo.ini') as path:
+ with open(path, 'w') as f:
+ f.write(simple)
+ pkg = os.path.splitext(path)[0]
out = read_config(pkg)
- self.assertTrue(out.cflags() == simple_d['cflags'])
- self.assertTrue(out.libs() == simple_d['libflags'])
- self.assertTrue(out.name == simple_d['name'])
- self.assertTrue(out.version == simple_d['version'])
- finally:
- os.remove(filename)
- def test_simple_variable(self):
- fd, filename = mkstemp('foo.ini')
- try:
- pkg = os.path.splitext(filename)[0]
- try:
- os.write(fd, simple_variable.encode('ascii'))
- finally:
- os.close(fd)
+ self.assertTrue(out.cflags() == simple_d['cflags'])
+ self.assertTrue(out.libs() == simple_d['libflags'])
+ self.assertTrue(out.name == simple_d['name'])
+ self.assertTrue(out.version == simple_d['version'])
+ def test_simple_variable(self):
+ with temppath('foo.ini') as path:
+ with open(path, 'w') as f:
+ f.write(simple_variable)
+ pkg = os.path.splitext(path)[0]
out = read_config(pkg)
- self.assertTrue(out.cflags() == simple_variable_d['cflags'])
- self.assertTrue(out.libs() == simple_variable_d['libflags'])
- self.assertTrue(out.name == simple_variable_d['name'])
- self.assertTrue(out.version == simple_variable_d['version'])
-
- out.vars['prefix'] = '/Users/david'
- self.assertTrue(out.cflags() == '-I/Users/david/include')
- finally:
- os.remove(filename)
+
+ self.assertTrue(out.cflags() == simple_variable_d['cflags'])
+ self.assertTrue(out.libs() == simple_variable_d['libflags'])
+ self.assertTrue(out.name == simple_variable_d['name'])
+ self.assertTrue(out.version == simple_variable_d['version'])
+ out.vars['prefix'] = '/Users/david'
+ self.assertTrue(out.cflags() == '-I/Users/david/include')
class TestParseFlags(TestCase):
def test_simple_cflags(self):
diff --git a/numpy/f2py/__init__.py b/numpy/f2py/__init__.py
index ef92114ed..50566ccc2 100644
--- a/numpy/f2py/__init__.py
+++ b/numpy/f2py/__init__.py
@@ -62,6 +62,6 @@ def compile(source,
f.close()
return status
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py
index 8d06d9680..0c9e91568 100644
--- a/numpy/f2py/tests/util.py
+++ b/numpy/f2py/tests/util.py
@@ -19,7 +19,7 @@ import random
from numpy.compat import asbytes, asstr
import numpy.f2py
-from numpy.testing import SkipTest
+from numpy.testing import SkipTest, temppath
try:
from hashlib import md5
@@ -159,16 +159,11 @@ def build_code(source_code, options=[], skip=[], only=[], suffix=None,
"""
if suffix is None:
suffix = '.f'
-
- fd, tmp_fn = tempfile.mkstemp(suffix=suffix)
- os.write(fd, asbytes(source_code))
- os.close(fd)
-
- try:
- return build_module([tmp_fn], options=options, skip=skip, only=only,
+ with temppath(suffix=suffix) as path:
+ with open(path, 'w') as f:
+ f.write(source_code)
+ return build_module([path], options=options, skip=skip, only=only,
module_name=module_name)
- finally:
- os.unlink(tmp_fn)
#
# Check if compilers are available at all...
@@ -209,22 +204,19 @@ sys.exit(99)
"""
code = code % dict(syspath=repr(sys.path))
- fd, script = tempfile.mkstemp(suffix='.py')
- os.write(fd, asbytes(code))
- os.close(fd)
+ with temppath(suffix='.py') as script:
+ with open(script, 'w') as f:
+ f.write(code)
- try:
cmd = [sys.executable, script, 'config']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, err = p.communicate()
- m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
- if m:
- _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
- bool(int(m.group(3))))
- finally:
- os.unlink(script)
+ m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out)
+ if m:
+ _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))),
+ bool(int(m.group(3))))
# Finished
return _compiler_status
diff --git a/numpy/fft/__init__.py b/numpy/fft/__init__.py
index 96809a94f..a1f9e90e0 100644
--- a/numpy/fft/__init__.py
+++ b/numpy/fft/__init__.py
@@ -6,6 +6,6 @@ from .info import __doc__
from .fftpack import *
from .helper import *
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py
index 0606dfbbd..1d65db55e 100644
--- a/numpy/lib/__init__.py
+++ b/numpy/lib/__init__.py
@@ -41,6 +41,6 @@ __all__ += npyio.__all__
__all__ += financial.__all__
__all__ += nanfunctions.__all__
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 45ee0a477..32e0c32de 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -4,7 +4,7 @@ import sys
import gzip
import os
import threading
-from tempfile import mkstemp, NamedTemporaryFile
+from tempfile import NamedTemporaryFile
import time
import warnings
import gc
@@ -194,8 +194,7 @@ class TestSavezLoad(RoundtripTest, TestCase):
def test_big_arrays(self):
L = (1 << 31) + 100000
a = np.empty(L, dtype=np.uint8)
- with tempdir(prefix="numpy_test_big_arrays_") as tmpdir:
- tmp = os.path.join(tmpdir, "file.npz")
+ with temppath(prefix="numpy_test_big_arrays_") as tmp:
np.savez(tmp, a=a)
del a
npfile = np.load(tmp)
@@ -234,16 +233,12 @@ class TestSavezLoad(RoundtripTest, TestCase):
# and savez functions in multithreaded environment
def writer(error_list):
- fd, tmp = mkstemp(suffix='.npz')
- os.close(fd)
- try:
+ with temppath(suffix='.npz') as tmp:
arr = np.random.randn(500, 500)
try:
np.savez(tmp, arr=arr)
except OSError as err:
error_list.append(err)
- finally:
- os.remove(tmp)
errors = []
threads = [threading.Thread(target=writer, args=(errors,))
@@ -277,13 +272,8 @@ class TestSavezLoad(RoundtripTest, TestCase):
# e.g. Debian sid of 2012 Jul 05 but was reported to
# trigger the failure on Ubuntu 10.04:
# http://projects.scipy.org/numpy/ticket/1517#comment:2
- fd, tmp = mkstemp(suffix='.npz')
- os.close(fd)
-
- try:
- fp = open(tmp, 'wb')
- np.savez(fp, data='LOVELY LOAD')
- fp.close()
+ with temppath(suffix='.npz') as tmp:
+ np.savez(tmp, data='LOVELY LOAD')
# We need to check if the garbage collector can properly close
# numpy npz file returned by np.load when their reference count
# goes to zero. Python 3 running in debug mode raises a
@@ -299,16 +289,14 @@ class TestSavezLoad(RoundtripTest, TestCase):
except Exception as e:
msg = "Failed to load data from a file: %s" % e
raise AssertionError(msg)
- finally:
- os.remove(tmp)
def test_closing_zipfile_after_load(self):
- # Check that zipfile owns file and can close it.
- # This needs to pass a file name to load for the
- # test.
- with tempdir(prefix="numpy_test_closing_zipfile_after_load_") as tmpdir:
- fd, tmp = mkstemp(suffix='.npz', dir=tmpdir)
- os.close(fd)
+ # Check that zipfile owns file and can close it. This needs to
+ # pass a file name to load for the test. On windows failure will
+ # cause a second error will be raised when the attempt to remove
+ # the open file is made.
+ prefix = 'numpy_test_closing_zipfile_after_load_'
+ with temppath(suffix='.npz', prefix=prefix) as tmp:
np.savez(tmp, lab='place holder')
data = np.load(tmp)
fp = data.zip.fp
@@ -416,15 +404,11 @@ class TestSaveTxt(TestCase):
asbytes('1 2\n3 4\n' + commentstr + test_header_footer + '\n'))
def test_file_roundtrip(self):
- f, name = mkstemp()
- os.close(f)
- try:
+ with temppath() as name:
a = np.array([(1, 2), (3, 4)])
np.savetxt(name, a)
b = np.loadtxt(name)
assert_array_equal(a, b)
- finally:
- os.unlink(name)
def test_complex_arrays(self):
ncols = 2
@@ -739,15 +723,11 @@ class TestLoadTxt(TestCase):
assert_equal(res, tgt)
def test_universal_newline(self):
- f, name = mkstemp()
- os.write(f, b'1 21\r3 42\r')
- os.close(f)
-
- try:
+ with temppath() as name:
+ with open(name, 'w') as f:
+ f.write('1 21\r3 42\r')
data = np.loadtxt(name)
- assert_array_equal(data, [[1, 21], [3, 42]])
- finally:
- os.unlink(name)
+ assert_array_equal(data, [[1, 21], [3, 42]])
def test_empty_field_after_tab(self):
c = TextIO()
@@ -1760,8 +1740,9 @@ M 33 21.99
assert_equal(test, control)
def test_gft_using_filename(self):
- # Test that we can load data from a filename as well as a file object
- wanted = np.arange(6).reshape((2, 3))
+ # Test that we can load data from a filename as well as a file
+ # object
+ tgt = np.arange(6).reshape((2, 3))
if sys.version_info[0] >= 3:
# python 3k is known to fail for '\r'
linesep = ('\n', '\r\n')
@@ -1770,15 +1751,11 @@ M 33 21.99
for sep in linesep:
data = '0 1 2' + sep + '3 4 5'
- f, name = mkstemp()
- # We can't use NamedTemporaryFile on windows, because we cannot
- # reopen the file.
- try:
- os.write(f, asbytes(data))
- assert_array_equal(np.genfromtxt(name), wanted)
- finally:
- os.close(f)
- os.unlink(name)
+ with temppath() as name:
+ with open(name, 'w') as f:
+ f.write(data)
+ res = np.genfromtxt(name)
+ assert_array_equal(res, tgt)
def test_gft_using_generator(self):
# gft doesn't work with unicode.
@@ -1838,16 +1815,15 @@ def test_gzip_loadtxt():
g = gzip.GzipFile(fileobj=s, mode='w')
g.write(b'1 2 3\n')
g.close()
+
s.seek(0)
+ with temppath(suffix='.gz') as name:
+ with open(name, 'wb') as f:
+ f.write(s.read())
+ res = np.loadtxt(name)
+ s.close()
- f, name = mkstemp(suffix='.gz')
- try:
- os.write(f, s.read())
- s.close()
- assert_array_equal(np.loadtxt(name), [1, 2, 3])
- finally:
- os.close(f)
- os.unlink(name)
+ assert_array_equal(res, [1, 2, 3])
def test_gzip_loadtxt_from_string():
diff --git a/numpy/linalg/__init__.py b/numpy/linalg/__init__.py
index bc2a1ff6c..69445f541 100644
--- a/numpy/linalg/__init__.py
+++ b/numpy/linalg/__init__.py
@@ -50,6 +50,6 @@ from .info import __doc__
from .linalg import *
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().test
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/ma/__init__.py b/numpy/ma/__init__.py
index 05b641dff..af3468b01 100644
--- a/numpy/ma/__init__.py
+++ b/numpy/ma/__init__.py
@@ -51,6 +51,6 @@ __all__ = ['core', 'extras']
__all__ += core.__all__
__all__ += extras.__all__
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index e0d9f072c..020bf1e62 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -201,7 +201,7 @@ class TestMaskedArray(TestCase):
assert_(not np.may_share_memory(x.mask, y.mask))
def test_creation_with_list_of_maskedarrays(self):
- # Tests creaating a masked array from alist of masked arrays.
+ # Tests creating a masked array from a list of masked arrays.
x = array(np.arange(5), mask=[1, 0, 0, 0, 0])
data = array((x, x[::-1]))
assert_equal(data, [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0]])
@@ -237,11 +237,6 @@ class TestMaskedArray(TestCase):
self.assertTrue(str(masked) == '--')
self.assertTrue(x[1] is masked)
assert_equal(filled(x[1], 0), 0)
- # don't know why these should raise an exception...
- #self.assertRaises(Exception, lambda x,y: x+y, masked, masked)
- #self.assertRaises(Exception, lambda x,y: x+y, masked, 2)
- #self.assertRaises(Exception, lambda x,y: x+y, masked, xx)
- #self.assertRaises(Exception, lambda x,y: x+y, xx, masked)
def test_set_element_as_object(self):
# Tests setting elements with object
@@ -360,10 +355,8 @@ class TestMaskedArray(TestCase):
x1 = np.arange(5)
y1 = array(x1, mask=m)
- #self.assertTrue( y1._data is x1)
assert_equal(y1._data.__array_interface__, x1.__array_interface__)
self.assertTrue(allequal(x1, y1.data))
- #self.assertTrue( y1.mask is m)
assert_equal(y1._mask.__array_interface__, m.__array_interface__)
y1a = array(y1)
@@ -373,12 +366,10 @@ class TestMaskedArray(TestCase):
y2 = array(x1, mask=m)
self.assertTrue(y2._data.__array_interface__ == x1.__array_interface__)
- #self.assertTrue( y2.mask is m)
self.assertTrue(y2._mask.__array_interface__ == m.__array_interface__)
self.assertTrue(y2[2] is masked)
y2[2] = 9
self.assertTrue(y2[2] is not masked)
- #self.assertTrue( y2.mask is not m)
self.assertTrue(y2._mask.__array_interface__ != m.__array_interface__)
self.assertTrue(allequal(y2.mask, 0))
@@ -1364,7 +1355,6 @@ class TestMaskedArrayAttributes(TestCase):
xs[[1, 4]] = [10, 40]
assert_equal(xh._data, [0, 10, 2, 3, 4])
assert_equal(xs._data, [0, 10, 2, 3, 40])
- #assert_equal(xh.mask.ctypes._data, m.ctypes._data)
assert_equal(xs.mask, [0, 0, 0, 1, 0])
self.assertTrue(xh._hardmask)
self.assertTrue(not xs._hardmask)
@@ -1372,7 +1362,6 @@ class TestMaskedArrayAttributes(TestCase):
xs[1:4] = [10, 20, 30]
assert_equal(xh._data, [0, 10, 20, 3, 4])
assert_equal(xs._data, [0, 10, 20, 30, 40])
- #assert_equal(xh.mask.ctypes._data, m.ctypes._data)
assert_equal(xs.mask, nomask)
xh[0] = masked
xs[0] = masked
@@ -1416,7 +1405,6 @@ class TestMaskedArrayAttributes(TestCase):
m = make_mask(n)
xh = array(d, mask=m, hard_mask=True)
xh[4:5] = 999
- #assert_equal(xh.mask.ctypes._data, m.ctypes._data)
xh[0:1] = 999
assert_equal(xh._data, [999, 1, 2, 3, 4])
@@ -1835,9 +1823,7 @@ class TestUfuncs(TestCase):
'arccosh',
'arctanh',
'absolute', 'fabs', 'negative',
- # 'nonzero', 'around',
'floor', 'ceil',
- # 'sometrue', 'alltrue',
'logical_not',
'add', 'subtract', 'multiply',
'divide', 'true_divide', 'floor_divide',
@@ -2060,15 +2046,12 @@ class TestMaskedArrayInPlaceArithmetics(TestCase):
assert_equal(z._mask, [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1])
assert_equal(z._data,
[1., 1., 1., -1., -pi / 2., 4., 5., 1., 1., 1., 2., 3.])
- #assert_equal(z._data, [0.2,1.,1./3.,-1.,-pi/2.,-1.,5.,1.,1.,1.,2.,1.])
xm = xm.copy()
xm /= ym
assert_equal(xm._mask, [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1])
assert_equal(z._data,
[1., 1., 1., -1., -pi / 2., 4., 5., 1., 1., 1., 2., 3.])
- #assert_equal(xm._data,
- # [1/5.,1.,1./3.,-1.,-pi/2.,-1.,5.,1.,1.,1.,2.,1.])
def test_datafriendly_add(self):
# Test keeping data w/ (inplace) addition
@@ -2497,7 +2480,7 @@ class TestMaskedArrayMethods(TestCase):
self.assertTrue(not allclose(a, b))
b[0] = np.inf
self.assertTrue(allclose(a, b))
- # Test all close w/ masked
+ # Test allclose w/ masked
a = masked_array(a)
a[-1] = masked
self.assertTrue(allclose(a, b, masked_equal=True))
@@ -2700,7 +2683,6 @@ class TestMaskedArrayMethods(TestCase):
self.assertTrue(x[3] is masked)
self.assertTrue(x[4] is masked)
x[[1, 4]] = [10, 40]
- #self.assertTrue(x.mask is not m)
self.assertTrue(x[3] is masked)
self.assertTrue(x[4] is not masked)
assert_equal(x, [0, 10, 2, -1, 40])
@@ -3875,10 +3857,6 @@ class TestMaskedArrayFunctions(TestCase):
# Using False as input
test = mask_or(mask, False)
assert_equal(test, mask)
- # Using True as input. Won't work, but keep it for the kicks
- # test = mask_or(mask, True)
- # control = np.array([(1, 1), (1, 1), (1, 1), (1, 1)], dtype=mtype)
- # assert_equal(test, control)
# Using another array w / the same dtype
other = np.array([(0, 1), (0, 1), (0, 1), (0, 1)], dtype=mtype)
test = mask_or(mask, other)
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index 84b68ba0f..574c65271 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -15,7 +15,7 @@ import numpy.ma as ma
from numpy import recarray
from numpy.compat import asbytes, asbytes_nested
from numpy.ma import masked, nomask
-from numpy.testing import TestCase, run_module_suite
+from numpy.testing import TestCase, run_module_suite, temppath
from numpy.core.records import (
fromrecords as recfromrecords, fromarrays as recfromarrays
)
@@ -476,7 +476,7 @@ class TestMRecordsImport(TestCase):
def test_fromtextfile(self):
# Tests reading from a text file.
- fcontent = asbytes(
+ fcontent = (
"""#
'One (S)','Two (I)','Three (F)','Four (M)','Five (-)','Six (C)'
'strings',1,1.0,'mixed column',,1
@@ -484,14 +484,10 @@ class TestMRecordsImport(TestCase):
'strings',3,3.0E5,3,,1
'strings',4,-1e-10,,,1
""")
- import os
- import tempfile
- (tmp_fd, tmp_fl) = tempfile.mkstemp()
- os.write(tmp_fd, fcontent)
- os.close(tmp_fd)
- mrectxt = fromtextfile(tmp_fl, delimitor=',', varnames='ABCDEFG')
- os.remove(tmp_fl)
-
+ with temppath() as path:
+ with open(path, 'w') as f:
+ f.write(fcontent)
+ mrectxt = fromtextfile(path, delimitor=',', varnames='ABCDEFG')
self.assertTrue(isinstance(mrectxt, MaskedRecords))
assert_equal(mrectxt.F, [1, 1, 1, 1])
assert_equal(mrectxt.E._mask, [1, 1, 1, 1])
diff --git a/numpy/matrixlib/__init__.py b/numpy/matrixlib/__init__.py
index d20696154..b2b76837a 100644
--- a/numpy/matrixlib/__init__.py
+++ b/numpy/matrixlib/__init__.py
@@ -7,6 +7,6 @@ from .defmatrix import *
__all__ = defmatrix.__all__
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/polynomial/__init__.py b/numpy/polynomial/__init__.py
index 1200d1c8d..82c350e9b 100644
--- a/numpy/polynomial/__init__.py
+++ b/numpy/polynomial/__init__.py
@@ -22,6 +22,6 @@ from .hermite import Hermite
from .hermite_e import HermiteE
from .laguerre import Laguerre
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/random/__init__.py b/numpy/random/__init__.py
index 388267c97..6c7d3140f 100644
--- a/numpy/random/__init__.py
+++ b/numpy/random/__init__.py
@@ -117,6 +117,6 @@ def __RandomState_ctor():
"""
return RandomState(seed=0)
-from numpy.testing import Tester
-test = Tester().test
-bench = Tester().bench
+from numpy.testing.nosetester import _numpy_tester
+test = _numpy_tester().test
+bench = _numpy_tester().bench
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index b83b2a588..110b60a9b 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -244,7 +244,6 @@ cdef object cont2_array(rk_state *state, rk_cont2 func, object size,
cdef double *oa_data
cdef double *ob_data
cdef ndarray array "arrayObject"
- cdef npy_intp length
cdef npy_intp i
cdef broadcast multi
@@ -300,7 +299,6 @@ cdef object cont3_array(rk_state *state, rk_cont3 func, object size,
cdef double *ob_data
cdef double *oc_data
cdef ndarray array "arrayObject"
- cdef npy_intp length
cdef npy_intp i
cdef broadcast multi
@@ -370,7 +368,6 @@ cdef object discnp_array(rk_state *state, rk_discnp func, object size,
ndarray on, ndarray op, object lock):
cdef long *array_data
cdef ndarray array "arrayObject"
- cdef npy_intp length
cdef npy_intp i
cdef double *op_data
cdef long *on_data
@@ -424,7 +421,6 @@ cdef object discdd_array(rk_state *state, rk_discdd func, object size,
ndarray on, ndarray op, object lock):
cdef long *array_data
cdef ndarray array "arrayObject"
- cdef npy_intp length
cdef npy_intp i
cdef double *op_data
cdef double *on_data
@@ -481,7 +477,6 @@ cdef object discnmN_array(rk_state *state, rk_discnmN func, object size,
cdef long *om_data
cdef long *oN_data
cdef ndarray array "arrayObject"
- cdef npy_intp length
cdef npy_intp i
cdef broadcast multi
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index c2e1adca3..a6783fe8f 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -248,7 +248,7 @@ class TestRandomDist(TestCase):
# Tests whether random_integers can generate the
# maximum allowed Python int that can be converted
# into a C long. Previous implementations of this
- # method have thrown an OverflowError when attemping
+ # method have thrown an OverflowError when attempting
# to generate this integer.
actual = np.random.random_integers(np.iinfo('l').max,
np.iinfo('l').max)
diff --git a/numpy/testing/__init__.py b/numpy/testing/__init__.py
index dcc02ad57..625fdecdc 100644
--- a/numpy/testing/__init__.py
+++ b/numpy/testing/__init__.py
@@ -12,4 +12,4 @@ from unittest import TestCase
from . import decorators as dec
from .nosetester import run_module_suite, NoseTester as Tester
from .utils import *
-test = Tester().test
+test = nosetester._numpy_tester().test
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
index 551e630ec..42113676a 100644
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -57,7 +57,7 @@ def import_nose():
""" Import nose only when needed.
"""
fine_nose = True
- minimum_nose_version = (0, 10, 0)
+ minimum_nose_version = (1, 0, 0)
try:
import nose
except ImportError:
@@ -158,15 +158,13 @@ class NoseTester(object):
- "develop" : equals ``(DeprecationWarning, RuntimeWarning)``
- "release" : equals ``()``, don't raise on any warnings.
- See Notes for more details.
-
- Notes
- -----
- The default for `raise_warnings` is
- ``(DeprecationWarning, RuntimeWarning)`` for development versions of NumPy,
- and ``()`` for released versions. The purpose of this switching behavior
- is to catch as many warnings as possible during development, but not give
- problems for packaging of released versions.
+ Default is "release".
+ depth : int, optional
+ If `package` is None, then this can be used to initialize from the
+ module of the caller of (the caller of (...)) the code that
+ initializes `NoseTester`. Default of 0 means the module of the
+ immediate caller; higher values are useful for utility routines that
+ want to initialize `NoseTester` objects on behalf of other code.
"""
# Stuff to exclude from tests. These are from numpy.distutils
@@ -176,16 +174,21 @@ class NoseTester(object):
'pyrex_ext',
'swig_ext']
- def __init__(self, package=None, raise_warnings=None):
- if raise_warnings is None and (
- not hasattr(np, '__version__') or '.dev0' in np.__version__):
- raise_warnings = "develop"
- elif raise_warnings is None:
+ def __init__(self, package=None, raise_warnings="release", depth=0):
+ # Back-compat: 'None' used to mean either "release" or "develop"
+ # depending on whether this was a release or develop version of
+ # numpy. Those semantics were fine for testing numpy, but not so
+ # helpful for downstream projects like scipy that use
+ # numpy.testing. (They want to set this based on whether *they* are a
+ # release or develop version, not whether numpy is.) So we continue to
+ # accept 'None' for back-compat, but it's now just an alias for the
+ # default "release".
+ if raise_warnings is None:
raise_warnings = "release"
package_name = None
if package is None:
- f = sys._getframe(1)
+ f = sys._getframe(1 + depth)
package_path = f.f_locals.get('__file__', None)
if package_path is None:
raise AssertionError
@@ -514,3 +517,10 @@ class NoseTester(object):
add_plugins = [Unplugger('doctest')]
return nose.run(argv=argv, addplugins=add_plugins)
+
+def _numpy_tester():
+ if hasattr(np, "__version__") and ".dev0" in np.__version__:
+ mode = "develop"
+ else:
+ mode = "release"
+ return NoseTester(raise_warnings=mode, depth=1)
diff --git a/numpy/tests/test_scripts.py b/numpy/tests/test_scripts.py
index 74efd2650..94587e807 100644
--- a/numpy/tests/test_scripts.py
+++ b/numpy/tests/test_scripts.py
@@ -14,7 +14,7 @@ from nose.tools import assert_equal
from numpy.testing.decorators import skipif
from numpy.testing import assert_
-skipif_inplace = skipif(isfile(pathjoin(dirname(np.__file__), '..', 'setup.py')))
+is_inplace = isfile(pathjoin(dirname(np.__file__), '..', 'setup.py'))
def run_command(cmd, check_code=True):
""" Run command sequence `cmd` returning exit code, stdout, stderr
@@ -58,7 +58,7 @@ def run_command(cmd, check_code=True):
return proc.returncode, stdout, stderr
-@skipif_inplace
+@skipif(is_inplace)
def test_f2py():
# test that we can run f2py script
if sys.platform == 'win32':
@@ -77,6 +77,7 @@ def test_f2py():
assert_equal(stdout.strip(), asbytes('2'))
success = True
break
- except OSError:
+ except:
pass
- assert_(success, "Warning: neither %s nor %s found in path" % f2py_cmds)
+ msg = "Warning: neither %s nor %s found in path" % f2py_cmds
+ assert_(success, msg)