summaryrefslogtreecommitdiff
path: root/numpy/matrixlib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/matrixlib/tests')
-rw-r--r--numpy/matrixlib/tests/test_defmatrix.py29
-rw-r--r--numpy/matrixlib/tests/test_interaction.py31
-rw-r--r--numpy/matrixlib/tests/test_masked_matrix.py8
-rw-r--r--numpy/matrixlib/tests/test_matrix_linalg.py2
-rw-r--r--numpy/matrixlib/tests/test_multiarray.py4
-rw-r--r--numpy/matrixlib/tests/test_numeric.py4
-rw-r--r--numpy/matrixlib/tests/test_regression.py4
7 files changed, 28 insertions, 54 deletions
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index aa6e08d64..4cb5f3a37 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -1,11 +1,4 @@
-from __future__ import division, absolute_import, print_function
-
-try:
- # Accessing collections abstract classes from collections
- # has been deprecated since Python 3.3
- import collections.abc as collections_abc
-except ImportError:
- import collections as collections_abc
+import collections.abc
import numpy as np
from numpy import matrix, asmatrix, bmat
@@ -16,7 +9,7 @@ from numpy.testing import (
from numpy.linalg import matrix_power
from numpy.matrixlib import mat
-class TestCtor(object):
+class TestCtor:
def test_basic(self):
A = np.array([[1, 2], [3, 4]])
mA = matrix(A)
@@ -63,7 +56,7 @@ class TestCtor(object):
assert_(np.all(b2 == mixresult))
-class TestProperties(object):
+class TestProperties:
def test_sum(self):
"""Test whether matrix.sum(axis=1) preserves orientation.
Fails in NumPy <= 0.9.6.2127.
@@ -196,7 +189,7 @@ class TestProperties(object):
B = matrix([[True], [True], [False]])
assert_array_equal(A, B)
-class TestCasting(object):
+class TestCasting:
def test_basic(self):
A = np.arange(100).reshape(10, 10)
mA = matrix(A)
@@ -215,7 +208,7 @@ class TestCasting(object):
assert_(np.all(mA != mB))
-class TestAlgebra(object):
+class TestAlgebra:
def test_basic(self):
import numpy.linalg as linalg
@@ -274,7 +267,7 @@ class TestAlgebra(object):
A*object()
-class TestMatrixReturn(object):
+class TestMatrixReturn:
def test_instance_methods(self):
a = matrix([1.0], dtype='f8')
methodargs = {
@@ -299,7 +292,7 @@ class TestMatrixReturn(object):
if attrib.startswith('_') or attrib in excluded_methods:
continue
f = getattr(a, attrib)
- if isinstance(f, collections_abc.Callable):
+ if isinstance(f, collections.abc.Callable):
# reset contents of a
a.astype('f8')
a.fill(1.0)
@@ -316,7 +309,7 @@ class TestMatrixReturn(object):
assert_(type(d) is np.ndarray)
-class TestIndexing(object):
+class TestIndexing:
def test_basic(self):
x = asmatrix(np.zeros((3, 2), float))
y = np.zeros((3, 1), float)
@@ -325,7 +318,7 @@ class TestIndexing(object):
assert_equal(x, [[0, 1], [0, 0], [0, 0]])
-class TestNewScalarIndexing(object):
+class TestNewScalarIndexing:
a = matrix([[1, 2], [3, 4]])
def test_dimesions(self):
@@ -392,7 +385,7 @@ class TestNewScalarIndexing(object):
assert_array_equal(x[[2, 1, 0],:], x[::-1,:])
-class TestPower(object):
+class TestPower:
def test_returntype(self):
a = np.array([[0, 1], [0, 0]])
assert_(type(matrix_power(a, 2)) is np.ndarray)
@@ -403,7 +396,7 @@ class TestPower(object):
assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]])
-class TestShape(object):
+class TestShape:
a = np.array([[1], [2]])
m = matrix([[1], [2]])
diff --git a/numpy/matrixlib/tests/test_interaction.py b/numpy/matrixlib/tests/test_interaction.py
index 088ae3c6a..5154bd621 100644
--- a/numpy/matrixlib/tests/test_interaction.py
+++ b/numpy/matrixlib/tests/test_interaction.py
@@ -2,8 +2,6 @@
Note that tests with MaskedArray and linalg are done in separate files.
"""
-from __future__ import division, absolute_import, print_function
-
import pytest
import textwrap
@@ -290,7 +288,7 @@ def test_kron_matrix():
assert_equal(type(np.kron(m, a)), np.matrix)
-class TestConcatenatorMatrix(object):
+class TestConcatenatorMatrix:
# 2018-04-29: moved here from core.tests.test_index_tricks.
def test_matrix(self):
a = [1, 2]
@@ -326,24 +324,17 @@ class TestConcatenatorMatrix(object):
def test_array_equal_error_message_matrix():
# 2018-04-29: moved here from testing.tests.test_utils.
- try:
+ with pytest.raises(AssertionError) as exc_info:
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")
+ msg = str(exc_info.value)
+ msg_reference = textwrap.dedent("""\
+
+ Arrays are not equal
+
+ (shapes (2,), (1, 2) mismatch)
+ x: array([1, 2])
+ y: matrix([[1, 2]])""")
+ assert_equal(msg, msg_reference)
def test_array_almost_equal_matrix():
diff --git a/numpy/matrixlib/tests/test_masked_matrix.py b/numpy/matrixlib/tests/test_masked_matrix.py
index d3911d2e1..45424ecf0 100644
--- a/numpy/matrixlib/tests/test_masked_matrix.py
+++ b/numpy/matrixlib/tests/test_masked_matrix.py
@@ -1,5 +1,3 @@
-from __future__ import division, absolute_import, print_function
-
import numpy as np
from numpy.ma.testutils import (assert_, assert_equal, assert_raises,
assert_array_equal)
@@ -29,7 +27,7 @@ class MMatrix(MaskedArray, np.matrix,):
return _view
-class TestMaskedMatrix(object):
+class TestMaskedMatrix:
def test_matrix_indexing(self):
# Tests conversions and indexing
x1 = np.matrix([[1, 2, 3], [4, 3, 2]])
@@ -171,7 +169,7 @@ class TestMaskedMatrix(object):
assert_(not isinstance(test, MaskedArray))
-class TestSubclassing(object):
+class TestSubclassing:
# Test suite for masked subclasses of ndarray.
def setup(self):
@@ -212,7 +210,7 @@ class TestSubclassing(object):
assert_(isinstance(divide(mx, x), MMatrix))
assert_equal(divide(mx, mx), divide(xmx, xmx))
-class TestConcatenator(object):
+class TestConcatenator:
# Tests for mr_, the equivalent of r_ for masked arrays.
def test_matrix_builder(self):
diff --git a/numpy/matrixlib/tests/test_matrix_linalg.py b/numpy/matrixlib/tests/test_matrix_linalg.py
index 6fc733c2e..106c2e382 100644
--- a/numpy/matrixlib/tests/test_matrix_linalg.py
+++ b/numpy/matrixlib/tests/test_matrix_linalg.py
@@ -1,6 +1,4 @@
""" Test functions for linalg module using the matrix class."""
-from __future__ import division, absolute_import, print_function
-
import numpy as np
from numpy.linalg.tests.test_linalg import (
diff --git a/numpy/matrixlib/tests/test_multiarray.py b/numpy/matrixlib/tests/test_multiarray.py
index 6d84bd477..638d0d153 100644
--- a/numpy/matrixlib/tests/test_multiarray.py
+++ b/numpy/matrixlib/tests/test_multiarray.py
@@ -1,9 +1,7 @@
-from __future__ import division, absolute_import, print_function
-
import numpy as np
from numpy.testing import assert_, assert_equal, assert_array_equal
-class TestView(object):
+class TestView:
def test_type(self):
x = np.array([1, 2, 3])
assert_(isinstance(x.view(np.matrix), np.matrix))
diff --git a/numpy/matrixlib/tests/test_numeric.py b/numpy/matrixlib/tests/test_numeric.py
index 95e1c8001..a772bb388 100644
--- a/numpy/matrixlib/tests/test_numeric.py
+++ b/numpy/matrixlib/tests/test_numeric.py
@@ -1,9 +1,7 @@
-from __future__ import division, absolute_import, print_function
-
import numpy as np
from numpy.testing import assert_equal
-class TestDot(object):
+class TestDot:
def test_matscalar(self):
b1 = np.matrix(np.ones((3, 3), dtype=complex))
assert_equal(b1*1.0, b1)
diff --git a/numpy/matrixlib/tests/test_regression.py b/numpy/matrixlib/tests/test_regression.py
index 70e147279..a54d44020 100644
--- a/numpy/matrixlib/tests/test_regression.py
+++ b/numpy/matrixlib/tests/test_regression.py
@@ -1,10 +1,8 @@
-from __future__ import division, absolute_import, print_function
-
import numpy as np
from numpy.testing import assert_, assert_equal, assert_raises
-class TestRegression(object):
+class TestRegression:
def test_kron_matrix(self):
# Ticket #71
x = np.matrix('[1 0; 1 0]')