summaryrefslogtreecommitdiff
path: root/numpy/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/tests')
-rw-r--r--numpy/core/tests/_locales.py76
-rw-r--r--numpy/core/tests/test_deprecations.py6
-rw-r--r--numpy/core/tests/test_dtype.py2
-rw-r--r--numpy/core/tests/test_extint128.py2
-rw-r--r--numpy/core/tests/test_indexing.py2
-rw-r--r--numpy/core/tests/test_longdouble.py84
-rw-r--r--numpy/core/tests/test_mem_overlap.py6
-rw-r--r--numpy/core/tests/test_multiarray.py150
-rw-r--r--numpy/core/tests/test_nditer.py13
-rw-r--r--numpy/core/tests/test_print.py53
-rw-r--r--numpy/core/tests/test_ufunc.py53
-rw-r--r--numpy/core/tests/test_umath.py2
12 files changed, 257 insertions, 192 deletions
diff --git a/numpy/core/tests/_locales.py b/numpy/core/tests/_locales.py
new file mode 100644
index 000000000..28eebb14d
--- /dev/null
+++ b/numpy/core/tests/_locales.py
@@ -0,0 +1,76 @@
+"""Provide class for testing in French locale
+
+"""
+from __future__ import division, absolute_import, print_function
+
+import sys
+import locale
+
+from numpy.testing import SkipTest
+
+__ALL__ = ['CommaDecimalPointLocale']
+
+
+def find_comma_decimal_point_locale():
+ """See if platform has a decimal point as comma locale.
+
+ Find a locale that uses a comma instead of a period as the
+ decimal point.
+
+ Returns
+ -------
+ old_locale: str
+ Locale when the function was called.
+ new_locale: {str, None)
+ First French locale found, None if none found.
+
+ """
+ if sys.platform == 'win32':
+ locales = ['FRENCH']
+ else:
+ locales = ['fr_FR', 'fr_FR.UTF-8', 'fi_FI', 'fi_FI.UTF-8']
+
+ old_locale = locale.getlocale(locale.LC_NUMERIC)
+ new_locale = None
+ try:
+ for loc in locales:
+ try:
+ locale.setlocale(locale.LC_NUMERIC, loc)
+ new_locale = loc
+ break
+ except locale.Error:
+ pass
+ finally:
+ locale.setlocale(locale.LC_NUMERIC, locale=old_locale)
+ return old_locale, new_locale
+
+
+class CommaDecimalPointLocale(object):
+ """Sets LC_NUMERIC to a locale with comma as decimal point.
+
+ Classes derived from this class have setup and teardown methods that run
+ tests with locale.LC_NUMERIC set to a locale where commas (',') are used as
+ the decimal point instead of periods ('.'). On exit the locale is restored
+ to the initial locale. It also serves as context manager with the same
+ effect. If no such locale is available, it raises SkipTest in both cases.
+
+ .. versionadded:: 1.15.0
+
+ """
+ (cur_locale, tst_locale) = find_comma_decimal_point_locale()
+
+ def setup(self):
+ if self.tst_locale is None:
+ raise SkipTest("No French locale available")
+ locale.setlocale(locale.LC_NUMERIC, locale=self.tst_locale)
+
+ def teardown(self):
+ locale.setlocale(locale.LC_NUMERIC, locale=self.cur_locale)
+
+ def __enter__(self):
+ if self.tst_locale is None:
+ raise SkipTest("No French locale available")
+ locale.setlocale(locale.LC_NUMERIC, locale=self.tst_locale)
+
+ def __exit__(self, type, value, traceback):
+ locale.setlocale(locale.LC_NUMERIC, locale=self.cur_locale)
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index fe0c7cc5f..2c2900e6c 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -429,7 +429,7 @@ class TestNonNumericConjugate(_DeprecationTestCase):
class TestNPY_CHAR(_DeprecationTestCase):
# 2017-05-03, 1.13.0
def test_npy_char_deprecation(self):
- from numpy.core.multiarray_tests import npy_char_deprecation
+ from numpy.core._multiarray_tests import npy_char_deprecation
self.assert_deprecated(npy_char_deprecation)
assert_(npy_char_deprecation() == 'S1')
@@ -440,11 +440,11 @@ class Test_UPDATEIFCOPY(_DeprecationTestCase):
WRITEBACKIFCOPY instead
"""
def test_npy_updateifcopy_deprecation(self):
- from numpy.core.multiarray_tests import npy_updateifcopy_deprecation
+ from numpy.core._multiarray_tests import npy_updateifcopy_deprecation
arr = np.arange(9).reshape(3, 3)
v = arr.T
self.assert_deprecated(npy_updateifcopy_deprecation, args=(v,))
-
+
class TestDatetimeEvent(_DeprecationTestCase):
# 2017-08-11, 1.14.0
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index 2f997b4f7..c924e6f43 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -5,7 +5,7 @@ import sys
import operator
import numpy as np
-from numpy.core.test_rational import rational
+from numpy.core._rational_tests import rational
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_raises,
dec
diff --git a/numpy/core/tests/test_extint128.py b/numpy/core/tests/test_extint128.py
index d87585dcf..31786124d 100644
--- a/numpy/core/tests/test_extint128.py
+++ b/numpy/core/tests/test_extint128.py
@@ -6,7 +6,7 @@ import contextlib
import operator
import numpy as np
-import numpy.core.multiarray_tests as mt
+import numpy.core._multiarray_tests as mt
from numpy.compat import long
from numpy.testing import assert_raises, assert_equal, dec
diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py
index 3a02c9fce..082ecb496 100644
--- a/numpy/core/tests/test_indexing.py
+++ b/numpy/core/tests/test_indexing.py
@@ -6,7 +6,7 @@ import functools
import operator
import numpy as np
-from numpy.core.multiarray_tests import array_indexing
+from numpy.core._multiarray_tests import array_indexing
from itertools import product
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_raises,
diff --git a/numpy/core/tests/test_longdouble.py b/numpy/core/tests/test_longdouble.py
index 625d40c1b..7cd5b04d8 100644
--- a/numpy/core/tests/test_longdouble.py
+++ b/numpy/core/tests/test_longdouble.py
@@ -7,7 +7,7 @@ from numpy.testing import (
run_module_suite, assert_, assert_equal, dec, assert_raises,
assert_array_equal, temppath,
)
-from .test_print import in_foreign_locale
+from ._locales import CommaDecimalPointLocale
LD_INFO = np.finfo(np.longdouble)
longdouble_longer_than_double = (LD_INFO.eps < np.finfo(np.double).eps)
@@ -50,25 +50,12 @@ def test_bytes():
np.longdouble(b"1.2")
-@in_foreign_locale
-def test_fromstring_foreign_repr():
- f = 1.234
- a = np.fromstring(repr(f), dtype=float, sep=" ")
- assert_equal(a[0], f)
-
-
@dec.knownfailureif(string_to_longdouble_inaccurate, "Need strtold_l")
def test_repr_roundtrip_bytes():
o = 1 + LD_INFO.eps
assert_equal(np.longdouble(repr(o).encode("ascii")), o)
-@in_foreign_locale
-def test_repr_roundtrip_foreign():
- o = 1.5
- assert_equal(o, np.longdouble(repr(o)))
-
-
def test_bogus_string():
assert_raises(ValueError, np.longdouble, "spam")
assert_raises(ValueError, np.longdouble, "1.0 flub")
@@ -83,18 +70,6 @@ def test_fromstring():
err_msg="reading '%s'" % s)
-@in_foreign_locale
-def test_fromstring_best_effort_float():
- assert_equal(np.fromstring("1,234", dtype=float, sep=" "),
- np.array([1.]))
-
-
-@in_foreign_locale
-def test_fromstring_best_effort():
- assert_equal(np.fromstring("1,234", dtype=np.longdouble, sep=" "),
- np.array([1.]))
-
-
def test_fromstring_bogus():
assert_equal(np.fromstring("1. 2. 3. flop 4.", dtype=float, sep=" "),
np.array([1., 2., 3.]))
@@ -155,26 +130,6 @@ class TestFileBased(object):
assert_equal(res, self.tgt)
-@in_foreign_locale
-def test_fromstring_foreign():
- s = "1.234"
- a = np.fromstring(s, dtype=np.longdouble, sep=" ")
- assert_equal(a[0], np.longdouble(s))
-
-
-@in_foreign_locale
-def test_fromstring_foreign_sep():
- a = np.array([1, 2, 3, 4])
- b = np.fromstring("1,2,3,4,", dtype=np.longdouble, sep=",")
- assert_array_equal(a, b)
-
-
-@in_foreign_locale
-def test_fromstring_foreign_value():
- b = np.fromstring("1,234", dtype=np.longdouble, sep=" ")
- assert_array_equal(b[0], 1)
-
-
# Conversions long double -> string
@@ -207,6 +162,43 @@ def test_array_repr():
raise ValueError("precision loss creating arrays")
assert_(repr(a) != repr(b))
+#
+# Locale tests: scalar types formatting should be independent of the locale
+#
+
+class TestCommaDecimalPointLocale(CommaDecimalPointLocale):
+
+ def test_repr_roundtrip_foreign(self):
+ o = 1.5
+ assert_equal(o, np.longdouble(repr(o)))
+
+ def test_fromstring_foreign_repr(self):
+ f = 1.234
+ a = np.fromstring(repr(f), dtype=float, sep=" ")
+ assert_equal(a[0], f)
+
+ def test_fromstring_best_effort_float(self):
+ assert_equal(np.fromstring("1,234", dtype=float, sep=" "),
+ np.array([1.]))
+
+ def test_fromstring_best_effort(self):
+ assert_equal(np.fromstring("1,234", dtype=np.longdouble, sep=" "),
+ np.array([1.]))
+
+ def test_fromstring_foreign(self):
+ s = "1.234"
+ a = np.fromstring(s, dtype=np.longdouble, sep=" ")
+ assert_equal(a[0], np.longdouble(s))
+
+ def test_fromstring_foreign_sep(self):
+ a = np.array([1, 2, 3, 4])
+ b = np.fromstring("1,2,3,4,", dtype=np.longdouble, sep=",")
+ assert_array_equal(a, b)
+
+ def test_fromstring_foreign_value(self):
+ b = np.fromstring("1,234", dtype=np.longdouble, sep=" ")
+ assert_array_equal(b[0], 1)
+
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py
index 9c17ed210..92baa0896 100644
--- a/numpy/core/tests/test_mem_overlap.py
+++ b/numpy/core/tests/test_mem_overlap.py
@@ -7,8 +7,8 @@ import numpy as np
from numpy.testing import (run_module_suite, assert_, assert_raises, assert_equal,
assert_array_equal, assert_allclose, dec)
-from numpy.core.multiarray_tests import solve_diophantine, internal_overlap
-from numpy.core import umath_tests
+from numpy.core._multiarray_tests import solve_diophantine, internal_overlap
+from numpy.core import _umath_tests
from numpy.lib.stride_tricks import as_strided
from numpy.compat import long
@@ -749,7 +749,7 @@ class TestUFunc(object):
def test_unary_gufunc_fuzz(self):
shapes = [7, 13, 8, 21, 29, 32]
- gufunc = umath_tests.euclidean_pdist
+ gufunc = _umath_tests.euclidean_pdist
rng = np.random.RandomState(1234)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 940072238..00e2a1e31 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -26,18 +26,14 @@ from decimal import Decimal
import numpy as np
from numpy.compat import strchar, unicode
-from numpy.core.tests.test_print import in_foreign_locale
-from numpy.core.multiarray_tests import (
- test_neighborhood_iterator, test_neighborhood_iterator_oob,
- test_pydatamem_seteventhook_start, test_pydatamem_seteventhook_end,
- test_inplace_increment, get_buffer_info, test_as_c_array,
- )
+import numpy.core._multiarray_tests as _multiarray_tests
from numpy.testing import (
run_module_suite, assert_, assert_raises, assert_warns,
assert_equal, assert_almost_equal, assert_array_equal, assert_raises_regex,
assert_array_almost_equal, assert_allclose, IS_PYPY, HAS_REFCOUNT,
assert_array_less, runstring, dec, SkipTest, temppath, suppress_warnings
)
+from ._locales import CommaDecimalPointLocale
# Need to test an object that does not fully implement math interface
from datetime import timedelta, datetime
@@ -195,7 +191,7 @@ class TestAttributes(object):
assert_equal(isinstance(numpy_int, int), True)
# ... and fast-path checks on C-API level should also work
- from numpy.core.multiarray_tests import test_int_subclass
+ from numpy.core._multiarray_tests import test_int_subclass
assert_equal(test_int_subclass(numpy_int), True)
def test_stridesattr(self):
@@ -3346,7 +3342,7 @@ class TestTemporaryElide(object):
# def incref_elide(a):
# d = input.copy() # refcount 1
# return d, d + d # PyNumber_Add without increasing refcount
- from numpy.core.multiarray_tests import incref_elide
+ from numpy.core._multiarray_tests import incref_elide
d = np.ones(100000)
orig, res = incref_elide(d)
d + d
@@ -3361,7 +3357,7 @@ class TestTemporaryElide(object):
#
# def incref_elide_l(d):
# return l[4] + l[4] # PyNumber_Add without increasing refcount
- from numpy.core.multiarray_tests import incref_elide_l
+ from numpy.core._multiarray_tests import incref_elide_l
# padding with 1 makes sure the object on the stack is not overwritten
l = [1, 1, 1, 1, np.ones(100000)]
res = incref_elide_l(l)
@@ -3440,7 +3436,7 @@ class TestTemporaryElide(object):
class TestCAPI(object):
def test_IsPythonScalar(self):
- from numpy.core.multiarray_tests import IsPythonScalar
+ from numpy.core._multiarray_tests import IsPythonScalar
assert_(IsPythonScalar(b'foobar'))
assert_(IsPythonScalar(1))
assert_(IsPythonScalar(2**80))
@@ -4477,14 +4473,15 @@ class TestIO(object):
assert_equal(s, '1.51,2.00,3.51,4.00')
def test_locale(self):
- in_foreign_locale(self.test_numbers)()
- in_foreign_locale(self.test_nan)()
- in_foreign_locale(self.test_inf)()
- in_foreign_locale(self.test_counted_string)()
- in_foreign_locale(self.test_ascii)()
- in_foreign_locale(self.test_malformed)()
- in_foreign_locale(self.test_tofile_sep)()
- in_foreign_locale(self.test_tofile_format)()
+ with CommaDecimalPointLocale():
+ self.test_numbers()
+ self.test_nan()
+ self.test_inf()
+ self.test_counted_string()
+ self.test_ascii()
+ self.test_malformed()
+ self.test_tofile_sep()
+ self.test_tofile_format()
class TestFromBuffer(object):
@@ -5808,24 +5805,24 @@ class TestNeighborhoodIter(object):
np.array([[0, 0, 0], [0, 1, 0]], dtype=dt),
np.array([[0, 0, 1], [0, 2, 3]], dtype=dt),
np.array([[0, 1, 0], [2, 3, 0]], dtype=dt)]
- l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0],
- NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 0, -1, 1], x[0], NEIGH_MODE['zero'])
assert_array_equal(l, r)
r = [np.array([[1, 1, 1], [1, 0, 1]], dtype=dt),
np.array([[1, 1, 1], [0, 1, 1]], dtype=dt),
np.array([[1, 0, 1], [1, 2, 3]], dtype=dt),
np.array([[0, 1, 1], [2, 3, 1]], dtype=dt)]
- l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0],
- NEIGH_MODE['one'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 0, -1, 1], x[0], NEIGH_MODE['one'])
assert_array_equal(l, r)
r = [np.array([[4, 4, 4], [4, 0, 1]], dtype=dt),
np.array([[4, 4, 4], [0, 1, 4]], dtype=dt),
np.array([[4, 0, 1], [4, 2, 3]], dtype=dt),
np.array([[0, 1, 4], [2, 3, 4]], dtype=dt)]
- l = test_neighborhood_iterator(x, [-1, 0, -1, 1], 4,
- NEIGH_MODE['constant'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant'])
assert_array_equal(l, r)
def test_simple2d(self):
@@ -5840,8 +5837,8 @@ class TestNeighborhoodIter(object):
np.array([[0, 1, 1], [0, 1, 1]], dtype=dt),
np.array([[0, 0, 1], [2, 2, 3]], dtype=dt),
np.array([[0, 1, 1], [2, 3, 3]], dtype=dt)]
- l = test_neighborhood_iterator(x, [-1, 0, -1, 1], x[0],
- NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 0, -1, 1], x[0], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
def test_mirror2d(self):
@@ -5855,15 +5852,18 @@ class TestNeighborhoodIter(object):
# Test padding with constant values
x = np.linspace(1, 5, 5).astype(dt)
r = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 0]]
- l = test_neighborhood_iterator(x, [-1, 1], x[0], NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 1], x[0], NEIGH_MODE['zero'])
assert_array_equal(l, r)
r = [[1, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 1]]
- l = test_neighborhood_iterator(x, [-1, 1], x[0], NEIGH_MODE['one'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 1], x[0], NEIGH_MODE['one'])
assert_array_equal(l, r)
r = [[x[4], 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, x[4]]]
- l = test_neighborhood_iterator(x, [-1, 1], x[4], NEIGH_MODE['constant'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-1, 1], x[4], NEIGH_MODE['constant'])
assert_array_equal(l, r)
def test_simple_float(self):
@@ -5877,7 +5877,8 @@ class TestNeighborhoodIter(object):
x = np.linspace(1, 5, 5).astype(dt)
r = np.array([[2, 1, 1, 2, 3], [1, 1, 2, 3, 4], [1, 2, 3, 4, 5],
[2, 3, 4, 5, 5], [3, 4, 5, 5, 4]], dtype=dt)
- l = test_neighborhood_iterator(x, [-2, 2], x[1], NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-2, 2], x[1], NEIGH_MODE['mirror'])
assert_([i.dtype == dt for i in l])
assert_array_equal(l, r)
@@ -5892,7 +5893,8 @@ class TestNeighborhoodIter(object):
x = np.linspace(1, 5, 5).astype(dt)
r = np.array([[4, 5, 1, 2, 3], [5, 1, 2, 3, 4], [1, 2, 3, 4, 5],
[2, 3, 4, 5, 1], [3, 4, 5, 1, 2]], dtype=dt)
- l = test_neighborhood_iterator(x, [-2, 2], x[0], NEIGH_MODE['circular'])
+ l = _multiarray_tests.test_neighborhood_iterator(
+ x, [-2, 2], x[0], NEIGH_MODE['circular'])
assert_array_equal(l, r)
def test_circular(self):
@@ -5915,8 +5917,8 @@ class TestStackedNeighborhoodIter(object):
np.array([3], dtype=dt),
np.array([0], dtype=dt),
np.array([0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-2, 4], NEIGH_MODE['zero'],
- [0, 0], NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-2, 4], NEIGH_MODE['zero'], [0, 0], NEIGH_MODE['zero'])
assert_array_equal(l, r)
r = [np.array([1, 0, 1], dtype=dt),
@@ -5924,8 +5926,8 @@ class TestStackedNeighborhoodIter(object):
np.array([1, 2, 3], dtype=dt),
np.array([2, 3, 0], dtype=dt),
np.array([3, 0, 1], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [-1, 1], NEIGH_MODE['one'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [-1, 1], NEIGH_MODE['one'])
assert_array_equal(l, r)
# 2nd simple, 1d test: stacking 2 neigh iterators, mixing const padding and
@@ -5939,8 +5941,8 @@ class TestStackedNeighborhoodIter(object):
np.array([1, 2, 3], dtype=dt),
np.array([2, 3, 3], dtype=dt),
np.array([3, 3, 0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['mirror'],
- [-1, 1], NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['mirror'], [-1, 1], NEIGH_MODE['zero'])
assert_array_equal(l, r)
# Stacking mirror on top of zero
@@ -5950,8 +5952,8 @@ class TestStackedNeighborhoodIter(object):
np.array([0, 1, 2], dtype=dt),
np.array([1, 2, 3], dtype=dt),
np.array([2, 3, 0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [-2, 0], NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [-2, 0], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
# Stacking mirror on top of zero: 2nd
@@ -5961,8 +5963,8 @@ class TestStackedNeighborhoodIter(object):
np.array([2, 3, 0], dtype=dt),
np.array([3, 0, 0], dtype=dt),
np.array([0, 0, 3], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [0, 2], NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [0, 2], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
# Stacking mirror on top of zero: 3rd
@@ -5972,8 +5974,8 @@ class TestStackedNeighborhoodIter(object):
np.array([0, 1, 2, 3, 0], dtype=dt),
np.array([1, 2, 3, 0, 0], dtype=dt),
np.array([2, 3, 0, 0, 3], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [-2, 2], NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [-2, 2], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
# 3rd simple, 1d test: stacking 2 neigh iterators, mixing const padding and
@@ -5987,8 +5989,8 @@ class TestStackedNeighborhoodIter(object):
np.array([1, 2, 3], dtype=dt),
np.array([2, 3, 1], dtype=dt),
np.array([3, 1, 0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['circular'],
- [-1, 1], NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['circular'], [-1, 1], NEIGH_MODE['zero'])
assert_array_equal(l, r)
# Stacking mirror on top of zero
@@ -5998,8 +6000,8 @@ class TestStackedNeighborhoodIter(object):
np.array([0, 1, 2], dtype=dt),
np.array([1, 2, 3], dtype=dt),
np.array([2, 3, 0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [-2, 0], NEIGH_MODE['circular'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [-2, 0], NEIGH_MODE['circular'])
assert_array_equal(l, r)
# Stacking mirror on top of zero: 2nd
@@ -6009,8 +6011,8 @@ class TestStackedNeighborhoodIter(object):
np.array([2, 3, 0], dtype=dt),
np.array([3, 0, 0], dtype=dt),
np.array([0, 0, 1], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [0, 2], NEIGH_MODE['circular'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [0, 2], NEIGH_MODE['circular'])
assert_array_equal(l, r)
# Stacking mirror on top of zero: 3rd
@@ -6020,8 +6022,8 @@ class TestStackedNeighborhoodIter(object):
np.array([0, 1, 2, 3, 0], dtype=dt),
np.array([1, 2, 3, 0, 0], dtype=dt),
np.array([2, 3, 0, 0, 1], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [-1, 3], NEIGH_MODE['zero'],
- [-2, 2], NEIGH_MODE['circular'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [-1, 3], NEIGH_MODE['zero'], [-2, 2], NEIGH_MODE['circular'])
assert_array_equal(l, r)
# 4th simple, 1d test: stacking 2 neigh iterators, but with lower iterator
@@ -6032,24 +6034,24 @@ class TestStackedNeighborhoodIter(object):
# array
x = np.array([1, 2, 3], dtype=dt)
r = [np.array([1, 2, 3, 0], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'],
- [-1, 2], NEIGH_MODE['zero'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['zero'])
assert_array_equal(l, r)
# Stacking mirror on top of zero, first neighborhood strictly inside the
# array
x = np.array([1, 2, 3], dtype=dt)
r = [np.array([1, 2, 3, 3], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'],
- [-1, 2], NEIGH_MODE['mirror'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['mirror'])
assert_array_equal(l, r)
# Stacking mirror on top of zero, first neighborhood strictly inside the
# array
x = np.array([1, 2, 3], dtype=dt)
r = [np.array([1, 2, 3, 1], dtype=dt)]
- l = test_neighborhood_iterator_oob(x, [1, 1], NEIGH_MODE['zero'],
- [-1, 2], NEIGH_MODE['circular'])
+ l = _multiarray_tests.test_neighborhood_iterator_oob(
+ x, [1, 1], NEIGH_MODE['zero'], [-1, 2], NEIGH_MODE['circular'])
assert_array_equal(l, r)
class TestWarnings(object):
@@ -6433,7 +6435,9 @@ class TestNewBufferProtocol(object):
def test_export_flags(self):
# Check SIMPLE flag, see also gh-3613 (exception should be BufferError)
- assert_raises(ValueError, get_buffer_info, np.arange(5)[::2], ('SIMPLE',))
+ assert_raises(ValueError,
+ _multiarray_tests.get_buffer_info,
+ np.arange(5)[::2], ('SIMPLE',))
def test_padding(self):
for j in range(8):
@@ -6489,10 +6493,12 @@ class TestNewBufferProtocol(object):
arr = np.ones((1, 10))
if arr.flags.f_contiguous:
- shape, strides = get_buffer_info(arr, ['F_CONTIGUOUS'])
+ shape, strides = _multiarray_tests.get_buffer_info(
+ arr, ['F_CONTIGUOUS'])
assert_(strides[0] == 8)
arr = np.ones((10, 1), order='F')
- shape, strides = get_buffer_info(arr, ['C_CONTIGUOUS'])
+ shape, strides = _multiarray_tests.get_buffer_info(
+ arr, ['C_CONTIGUOUS'])
assert_(strides[-1] == 8)
def test_out_of_order_fields(self):
@@ -6634,26 +6640,26 @@ def test_scalar_element_deletion():
class TestMemEventHook(object):
def test_mem_seteventhook(self):
# The actual tests are within the C code in
- # multiarray/multiarray_tests.c.src
- test_pydatamem_seteventhook_start()
+ # multiarray/_multiarray_tests.c.src
+ _multiarray_tests.test_pydatamem_seteventhook_start()
# force an allocation and free of a numpy array
# needs to be larger then limit of small memory cacher in ctors.c
a = np.zeros(1000)
del a
gc.collect()
- test_pydatamem_seteventhook_end()
+ _multiarray_tests.test_pydatamem_seteventhook_end()
class TestMapIter(object):
def test_mapiter(self):
# The actual tests are within the C code in
- # multiarray/multiarray_tests.c.src
+ # multiarray/_multiarray_tests.c.src
a = np.arange(12).reshape((3, 4)).astype(float)
index = ([1, 1, 2, 0],
[0, 0, 2, 3])
vals = [50, 50, 30, 16]
- test_inplace_increment(a, index, vals)
+ _multiarray_tests.test_inplace_increment(a, index, vals)
assert_equal(a, [[0.00, 1., 2.0, 19.],
[104., 5., 6.0, 7.0],
[8.00, 9., 40., 11.]])
@@ -6661,24 +6667,24 @@ class TestMapIter(object):
b = np.arange(6).astype(float)
index = (np.array([1, 2, 0]),)
vals = [50, 4, 100.1]
- test_inplace_increment(b, index, vals)
+ _multiarray_tests.test_inplace_increment(b, index, vals)
assert_equal(b, [100.1, 51., 6., 3., 4., 5.])
class TestAsCArray(object):
def test_1darray(self):
array = np.arange(24, dtype=np.double)
- from_c = test_as_c_array(array, 3)
+ from_c = _multiarray_tests.test_as_c_array(array, 3)
assert_equal(array[3], from_c)
def test_2darray(self):
array = np.arange(24, dtype=np.double).reshape(3, 8)
- from_c = test_as_c_array(array, 2, 4)
+ from_c = _multiarray_tests.test_as_c_array(array, 2, 4)
assert_equal(array[2, 4], from_c)
def test_3darray(self):
array = np.arange(24, dtype=np.double).reshape(2, 3, 4)
- from_c = test_as_c_array(array, 1, 2, 3)
+ from_c = _multiarray_tests.test_as_c_array(array, 1, 2, 3)
assert_equal(array[1, 2, 3], from_c)
@@ -7238,7 +7244,7 @@ class TestWritebackIfCopy(object):
assert_equal(b, np.array([[15, 18, 21], [42, 54, 66], [69, 90, 111]]))
def test_view_assign(self):
- from numpy.core.multiarray_tests import npy_create_writebackifcopy, npy_resolve
+ from numpy.core._multiarray_tests import npy_create_writebackifcopy, npy_resolve
arr = np.arange(9).reshape(3, 3).T
arr_wb = npy_create_writebackifcopy(arr)
assert_(arr_wb.flags.writebackifcopy)
@@ -7308,7 +7314,7 @@ def test_equal_override():
def test_npymath_complex():
# Smoketest npymath functions
- from numpy.core.multiarray_tests import (
+ from numpy.core._multiarray_tests import (
npy_cabs, npy_carg)
funcs = {npy_cabs: np.absolute,
@@ -7327,7 +7333,7 @@ def test_npymath_complex():
def test_npymath_real():
# Smoketest npymath functions
- from numpy.core.multiarray_tests import (
+ from numpy.core._multiarray_tests import (
npy_log10, npy_cosh, npy_sinh, npy_tan, npy_tanh)
funcs = {npy_log10: np.log10,
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index 1b2485a87..9d8f4f06a 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -4,8 +4,8 @@ import sys
import warnings
import numpy as np
+import numpy.core._multiarray_tests as _multiarray_tests
from numpy import array, arange, nditer, all
-from numpy.core.multiarray_tests import test_nditer_too_large
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_array_equal,
assert_raises, assert_warns, dec, HAS_REFCOUNT, suppress_warnings
@@ -2697,18 +2697,19 @@ def test_iter_too_large_with_multiindex():
# arrays are now too large to be broadcast. The different modes test
# different nditer functionality with or without GIL.
for mode in range(6):
- assert_raises(ValueError, test_nditer_too_large, arrays, -1, mode)
+ with assert_raises(ValueError):
+ _multiarray_tests.test_nditer_too_large(arrays, -1, mode)
# but if we do nothing with the nditer, it can be constructed:
- test_nditer_too_large(arrays, -1, 7)
+ _multiarray_tests.test_nditer_too_large(arrays, -1, 7)
# When an axis is removed, things should work again (half the time):
for i in range(num):
for mode in range(6):
# an axis with size 1024 is removed:
- test_nditer_too_large(arrays, i*2, mode)
+ _multiarray_tests.test_nditer_too_large(arrays, i*2, mode)
# an axis with size 1 is removed:
- assert_raises(ValueError, test_nditer_too_large,
- arrays, i*2 + 1, mode)
+ with assert_raises(ValueError):
+ _multiarray_tests.test_nditer_too_large(arrays, i*2 + 1, mode)
if __name__ == "__main__":
diff --git a/numpy/core/tests/test_print.py b/numpy/core/tests/test_print.py
index 6ebb4733c..f432711a9 100644
--- a/numpy/core/tests/test_print.py
+++ b/numpy/core/tests/test_print.py
@@ -2,12 +2,14 @@ from __future__ import division, absolute_import, print_function
import sys
import locale
+import contextlib
import nose
import numpy as np
from numpy.testing import (
- run_module_suite, assert_, assert_equal, SkipTest
+ run_module_suite, assert_, assert_equal, SkipTest, dec
)
+from ._locales import CommaDecimalPointLocale
if sys.version_info[0] >= 3:
@@ -201,46 +203,21 @@ def test_scalar_format():
(fmat, repr(val), repr(valtype), str(e)))
+#
# Locale tests: scalar types formatting should be independent of the locale
-def in_foreign_locale(func):
- """
- Swap LC_NUMERIC locale to one in which the decimal point is ',' and not '.'
- If not possible, raise SkipTest
+#
- """
- if sys.platform == 'win32':
- locales = ['FRENCH']
- else:
- locales = ['fr_FR', 'fr_FR.UTF-8', 'fi_FI', 'fi_FI.UTF-8']
+class TestCommaDecimalPointLocale(CommaDecimalPointLocale):
+
+ def test_locale_single(self):
+ assert_equal(str(np.float32(1.2)), str(float(1.2)))
+
+ def test_locale_double(self):
+ assert_equal(str(np.double(1.2)), str(float(1.2)))
+
+ def test_locale_longdouble(self):
+ assert_equal(str(np.longdouble('1.2')), str(float(1.2)))
- def wrapper(*args, **kwargs):
- curloc = locale.getlocale(locale.LC_NUMERIC)
- try:
- for loc in locales:
- try:
- locale.setlocale(locale.LC_NUMERIC, loc)
- break
- except locale.Error:
- pass
- else:
- raise SkipTest("Skipping locale test, because "
- "French locale not found")
- return func(*args, **kwargs)
- finally:
- locale.setlocale(locale.LC_NUMERIC, locale=curloc)
- return nose.tools.make_decorator(func)(wrapper)
-
-@in_foreign_locale
-def test_locale_single():
- assert_equal(str(np.float32(1.2)), str(float(1.2)))
-
-@in_foreign_locale
-def test_locale_double():
- assert_equal(str(np.double(1.2)), str(float(1.2)))
-
-@in_foreign_locale
-def test_locale_longdouble():
- assert_equal(str(np.longdouble('1.2')), str(float(1.2)))
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 7e1bfbdbe..b690c8132 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -4,9 +4,9 @@ import warnings
import itertools
import numpy as np
-import numpy.core.umath_tests as umt
-import numpy.core.operand_flag_tests as opflag_tests
-from numpy.core.test_rational import rational, test_add, test_add_rationals
+import numpy.core._umath_tests as umt
+import numpy.core._operand_flag_tests as opflag_tests
+import numpy.core._rational_tests as _rational_tests
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_raises,
assert_array_equal, assert_almost_equal, assert_array_almost_equal,
@@ -42,8 +42,9 @@ class TestUfunc(object):
assert_(pickle.loads(pickle.dumps(np.sin)) is np.sin)
# Check that ufunc not defined in the top level numpy namespace such as
- # numpy.core.test_rational.test_add can also be pickled
- assert_(pickle.loads(pickle.dumps(test_add)) is test_add)
+ # numpy.core._rational_tests.test_add can also be pickled
+ res = pickle.loads(pickle.dumps(_rational_tests.test_add))
+ assert_(res is _rational_tests.test_add)
def test_pickle_withstring(self):
import pickle
@@ -1143,15 +1144,17 @@ class TestUfunc(object):
a = np.array([0, 1, 2], dtype='i8')
b = np.array([0, 1, 2], dtype='i8')
- c = np.empty(3, dtype=rational)
+ c = np.empty(3, dtype=_rational_tests.rational)
# Output must be specified so numpy knows what
# ufunc signature to look for
- result = test_add(a, b, c)
- assert_equal(result, np.array([0, 2, 4], dtype=rational))
+ result = _rational_tests.test_add(a, b, c)
+ target = np.array([0, 2, 4], dtype=_rational_tests.rational)
+ assert_equal(result, target)
# no output type should raise TypeError
- assert_raises(TypeError, test_add, a, b)
+ with assert_raises(TypeError):
+ _rational_tests.test_add(a, b)
def test_operand_flags(self):
a = np.arange(16, dtype='l').reshape(4, 4)
@@ -1167,7 +1170,7 @@ class TestUfunc(object):
assert_equal(a, 10)
def test_struct_ufunc(self):
- import numpy.core.struct_ufunc_test as struct_ufunc
+ import numpy.core._struct_ufunc_tests as struct_ufunc
a = np.array([(1, 2, 3)], dtype='u8,u8,u8')
b = np.array([(1, 2, 3)], dtype='u8,u8,u8')
@@ -1176,20 +1179,30 @@ class TestUfunc(object):
assert_equal(result, np.array([(2, 4, 6)], dtype='u8,u8,u8'))
def test_custom_ufunc(self):
- a = np.array([rational(1, 2), rational(1, 3), rational(1, 4)],
- dtype=rational)
- b = np.array([rational(1, 2), rational(1, 3), rational(1, 4)],
- dtype=rational)
-
- result = test_add_rationals(a, b)
- expected = np.array([rational(1), rational(2, 3), rational(1, 2)],
- dtype=rational)
+ a = np.array(
+ [_rational_tests.rational(1, 2),
+ _rational_tests.rational(1, 3),
+ _rational_tests.rational(1, 4)],
+ dtype=_rational_tests.rational)
+ b = np.array(
+ [_rational_tests.rational(1, 2),
+ _rational_tests.rational(1, 3),
+ _rational_tests.rational(1, 4)],
+ dtype=_rational_tests.rational)
+
+ result = _rational_tests.test_add_rationals(a, b)
+ expected = np.array(
+ [_rational_tests.rational(1),
+ _rational_tests.rational(2, 3),
+ _rational_tests.rational(1, 2)],
+ dtype=_rational_tests.rational)
assert_equal(result, expected)
def test_custom_ufunc_forced_sig(self):
# gh-9351 - looking for a non-first userloop would previously hang
- assert_raises(TypeError,
- np.multiply, rational(1), 1, signature=(rational, int, None))
+ with assert_raises(TypeError):
+ np.multiply(_rational_tests.rational(1), 1,
+ signature=(_rational_tests.rational, int, None))
def test_custom_array_like(self):
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 4b6b26cbf..fe7768e53 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -7,7 +7,7 @@ import fnmatch
import itertools
import numpy.core.umath as ncu
-from numpy.core import umath_tests as ncu_tests
+from numpy.core import _umath_tests as ncu_tests
import numpy as np
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_raises,