summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-04-29 17:37:16 -0400
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2018-04-29 17:38:01 -0400
commit4819af522b547719c3b8c50ef01fa738704e1690 (patch)
tree8b8b4f40dcdf5897f785e92aad183c4d99e0bfb3 /numpy
parent1394d0a723832d22ca749e402975786c7707fe02 (diff)
downloadnumpy-4819af522b547719c3b8c50ef01fa738704e1690.tar.gz
MAINT: move matrix tests in testing to matrixlib.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/matrixlib/tests/test_interaction.py42
-rw-r--r--numpy/testing/tests/test_utils.py32
2 files changed, 43 insertions, 31 deletions
diff --git a/numpy/matrixlib/tests/test_interaction.py b/numpy/matrixlib/tests/test_interaction.py
index e6135eb18..fefb159c6 100644
--- a/numpy/matrixlib/tests/test_interaction.py
+++ b/numpy/matrixlib/tests/test_interaction.py
@@ -4,12 +4,13 @@ Note that tests with MaskedArray and linalg are done in separate files.
"""
from __future__ import division, absolute_import, print_function
+import textwrap
import warnings
import numpy as np
from numpy.testing import (assert_, assert_equal, assert_raises,
assert_raises_regex, assert_array_equal,
- assert_almost_equal)
+ assert_almost_equal, assert_array_almost_equal)
def test_fancy_indexing():
@@ -319,3 +320,42 @@ class TestConcatenatorMatrix(object):
assert_equal(actual, expected)
assert_equal(type(actual), type(expected))
+
+
+def test_array_equal_error_message_matrix():
+ # 2018-04-29: moved here from testing.tests.test_utils.
+ try:
+ assert_equal(np.array([1, 2]), np.matrix([1, 2]))
+ except AssertionError as e:
+ msg = str(e)
+ msg2 = msg.replace("shapes (2L,), (1L, 2L)", "shapes (2,), (1, 2)")
+ msg_reference = textwrap.dedent("""\
+
+ Arrays are not equal
+
+ (shapes (2,), (1, 2) mismatch)
+ x: array([1, 2])
+ y: matrix([[1, 2]])""")
+ try:
+ assert_equal(msg, msg_reference)
+ except AssertionError:
+ assert_equal(msg2, msg_reference)
+ else:
+ raise AssertionError("Did not raise")
+
+
+def test_array_almost_equal_matrix():
+ # Matrix slicing keeps things 2-D, while array does not necessarily.
+ # See gh-8452.
+ # 2018-04-29: moved here from testing.tests.test_utils.
+ m1 = np.matrix([[1., 2.]])
+ m2 = np.matrix([[1., np.nan]])
+ m3 = np.matrix([[1., -np.inf]])
+ m4 = np.matrix([[np.nan, np.inf]])
+ m5 = np.matrix([[1., 2.], [np.nan, np.inf]])
+ for assert_func in assert_array_almost_equal, assert_almost_equal:
+ for m in m1, m2, m3, m4, m5:
+ assert_func(m, m)
+ a = np.array(m)
+ assert_func(a, m)
+ assert_func(m, a)
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py
index 0592e62f8..c9e8384c2 100644
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -286,7 +286,7 @@ class TestEqual(TestArrayEqual):
def test_error_message(self):
try:
- self._assert_func(np.array([1, 2]), np.matrix([1, 2]))
+ self._assert_func(np.array([1, 2]), np.array([[1, 2]]))
except AssertionError as e:
msg = str(e)
msg2 = msg.replace("shapes (2L,), (1L, 2L)", "shapes (2,), (1, 2)")
@@ -296,7 +296,7 @@ class TestEqual(TestArrayEqual):
(shapes (2,), (1, 2) mismatch)
x: array([1, 2])
- y: matrix([[1, 2]])""")
+ y: array([[1, 2]])""")
try:
assert_equal(msg, msg_reference)
except AssertionError:
@@ -366,20 +366,6 @@ class TestArrayAlmostEqual(_GenericTest):
self._assert_func(b, a)
self._assert_func(b, b)
- def test_matrix(self):
- # Matrix slicing keeps things 2-D, while array does not necessarily.
- # See gh-8452.
- m1 = np.matrix([[1., 2.]])
- m2 = np.matrix([[1., np.nan]])
- m3 = np.matrix([[1., -np.inf]])
- m4 = np.matrix([[np.nan, np.inf]])
- m5 = np.matrix([[1., 2.], [np.nan, np.inf]])
- for m in m1, m2, m3, m4, m5:
- self._assert_func(m, m)
- a = np.array(m)
- self._assert_func(a, m)
- self._assert_func(m, a)
-
def test_subclass_that_cannot_be_bool(self):
# While we cannot guarantee testing functions will always work for
# subclasses, the tests should ideally rely only on subclasses having
@@ -479,20 +465,6 @@ class TestAlmostEqual(_GenericTest):
# remove anything that's not the array string
assert_equal(str(e).split('%)\n ')[1], b)
- def test_matrix(self):
- # Matrix slicing keeps things 2-D, while array does not necessarily.
- # See gh-8452.
- m1 = np.matrix([[1., 2.]])
- m2 = np.matrix([[1., np.nan]])
- m3 = np.matrix([[1., -np.inf]])
- m4 = np.matrix([[np.nan, np.inf]])
- m5 = np.matrix([[1., 2.], [np.nan, np.inf]])
- for m in m1, m2, m3, m4, m5:
- self._assert_func(m, m)
- a = np.array(m)
- self._assert_func(a, m)
- self._assert_func(m, a)
-
def test_subclass_that_cannot_be_bool(self):
# While we cannot guarantee testing functions will always work for
# subclasses, the tests should ideally rely only on subclasses having