diff options
Diffstat (limited to 'numpy/matrixlib/tests')
-rw-r--r-- | numpy/matrixlib/tests/__init__.py | 0 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_defmatrix.py | 35 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_multiarray.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_numeric.py | 4 | ||||
-rw-r--r-- | numpy/matrixlib/tests/test_regression.py | 21 |
5 files changed, 35 insertions, 29 deletions
diff --git a/numpy/matrixlib/tests/__init__.py b/numpy/matrixlib/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/numpy/matrixlib/tests/__init__.py diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py index fd36d7770..77f262031 100644 --- a/numpy/matrixlib/tests/test_defmatrix.py +++ b/numpy/matrixlib/tests/test_defmatrix.py @@ -5,13 +5,13 @@ import collections import numpy as np from numpy import matrix, asmatrix, bmat from numpy.testing import ( - TestCase, run_module_suite, assert_, assert_equal, assert_almost_equal, + run_module_suite, assert_, assert_equal, assert_almost_equal, assert_array_equal, assert_array_almost_equal, assert_raises ) from numpy.matrixlib.defmatrix import matrix_power from numpy.matrixlib import mat -class TestCtor(TestCase): +class TestCtor(object): def test_basic(self): A = np.array([[1, 2], [3, 4]]) mA = matrix(A) @@ -58,7 +58,7 @@ class TestCtor(TestCase): assert_(np.all(b2 == mixresult)) -class TestProperties(TestCase): +class TestProperties(object): def test_sum(self): """Test whether matrix.sum(axis=1) preserves orientation. Fails in NumPy <= 0.9.6.2127. @@ -191,7 +191,7 @@ class TestProperties(TestCase): B = matrix([[True], [True], [False]]) assert_array_equal(A, B) -class TestCasting(TestCase): +class TestCasting(object): def test_basic(self): A = np.arange(100).reshape(10, 10) mA = matrix(A) @@ -210,7 +210,7 @@ class TestCasting(TestCase): assert_(np.all(mA != mB)) -class TestAlgebra(TestCase): +class TestAlgebra(object): def test_basic(self): import numpy.linalg as linalg @@ -249,6 +249,12 @@ class TestAlgebra(TestCase): assert_array_almost_equal(m4, np.dot(m2, m2)) assert_array_almost_equal(np.dot(mi, m), np.eye(2)) + def test_scalar_type_pow(self): + m = matrix([[1, 2], [3, 4]]) + for scalar_t in [np.int8, np.uint8]: + two = scalar_t(2) + assert_array_almost_equal(m ** 2, m ** two) + def test_notimplemented(self): '''Check that 'not implemented' operations produce a failure.''' A = matrix([[1., 2.], @@ -271,7 +277,7 @@ class TestAlgebra(TestCase): self.fail("matrix.__mul__ with non-numeric object doesn't raise" "a TypeError") -class TestMatrixReturn(TestCase): +class TestMatrixReturn(object): def test_instance_methods(self): a = matrix([1.0], dtype='f8') methodargs = { @@ -313,7 +319,7 @@ class TestMatrixReturn(TestCase): assert_(type(d) is np.ndarray) -class TestIndexing(TestCase): +class TestIndexing(object): def test_basic(self): x = asmatrix(np.zeros((3, 2), float)) y = np.zeros((3, 1), float) @@ -322,9 +328,8 @@ class TestIndexing(TestCase): assert_equal(x, [[0, 1], [0, 0], [0, 0]]) -class TestNewScalarIndexing(TestCase): - def setUp(self): - self.a = matrix([[1, 2], [3, 4]]) +class TestNewScalarIndexing(object): + a = matrix([[1, 2], [3, 4]]) def test_dimesions(self): a = self.a @@ -390,7 +395,7 @@ class TestNewScalarIndexing(TestCase): assert_array_equal(x[[2, 1, 0],:], x[::-1,:]) -class TestPower(TestCase): +class TestPower(object): def test_returntype(self): a = np.array([[0, 1], [0, 0]]) assert_(type(matrix_power(a, 2)) is np.ndarray) @@ -401,10 +406,10 @@ class TestPower(TestCase): assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]]) -class TestShape(TestCase): - def setUp(self): - self.a = np.array([[1], [2]]) - self.m = matrix([[1], [2]]) +class TestShape(object): + + a = np.array([[1], [2]]) + m = matrix([[1], [2]]) def test_shape(self): assert_equal(self.a.shape, (2, 1)) diff --git a/numpy/matrixlib/tests/test_multiarray.py b/numpy/matrixlib/tests/test_multiarray.py index d27e24ec9..bf891a196 100644 --- a/numpy/matrixlib/tests/test_multiarray.py +++ b/numpy/matrixlib/tests/test_multiarray.py @@ -2,10 +2,10 @@ from __future__ import division, absolute_import, print_function import numpy as np from numpy.testing import ( - TestCase, run_module_suite, assert_, assert_equal, assert_array_equal + run_module_suite, assert_, assert_equal, assert_array_equal ) -class TestView(TestCase): +class TestView(object): 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 28329da39..b826b8e81 100644 --- a/numpy/matrixlib/tests/test_numeric.py +++ b/numpy/matrixlib/tests/test_numeric.py @@ -1,9 +1,9 @@ from __future__ import division, absolute_import, print_function import numpy as np -from numpy.testing import assert_equal, TestCase, run_module_suite +from numpy.testing import assert_equal, run_module_suite -class TestDot(TestCase): +class TestDot(object): 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 0839fbf28..32cb38ac7 100644 --- a/numpy/matrixlib/tests/test_regression.py +++ b/numpy/matrixlib/tests/test_regression.py @@ -1,17 +1,18 @@ from __future__ import division, absolute_import, print_function import numpy as np -from numpy.testing import TestCase, run_module_suite, assert_, assert_equal +from numpy.testing import ( + run_module_suite, assert_, assert_equal, assert_raises + ) -rlevel = 1 -class TestRegression(TestCase): - def test_kron_matrix(self, level=rlevel): +class TestRegression(object): + def test_kron_matrix(self): # Ticket #71 x = np.matrix('[1 0; 1 0]') assert_equal(type(np.kron(x, x)), type(x)) - def test_matrix_properties(self,level=rlevel): + def test_matrix_properties(self): # Ticket #125 a = np.matrix([1.0], dtype=float) assert_(type(a.real) is np.matrix) @@ -20,18 +21,18 @@ class TestRegression(TestCase): assert_(type(c) is np.ndarray) assert_(type(d) is np.ndarray) - def test_matrix_multiply_by_1d_vector(self, level=rlevel): + def test_matrix_multiply_by_1d_vector(self): # Ticket #473 def mul(): np.mat(np.eye(2))*np.ones(2) - self.assertRaises(ValueError, mul) + assert_raises(ValueError, mul) - def test_matrix_std_argmax(self,level=rlevel): + def test_matrix_std_argmax(self): # Ticket #83 x = np.asmatrix(np.random.uniform(0, 1, (3, 3))) - self.assertEqual(x.std().shape, ()) - self.assertEqual(x.argmax().shape, ()) + assert_equal(x.std().shape, ()) + assert_equal(x.argmax().shape, ()) if __name__ == "__main__": run_module_suite() |