diff options
Diffstat (limited to 'numpy/polynomial/tests/test_polynomial.py')
-rw-r--r-- | numpy/polynomial/tests/test_polynomial.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/numpy/polynomial/tests/test_polynomial.py b/numpy/polynomial/tests/test_polynomial.py index 1436963c6..5fd1a82a2 100644 --- a/numpy/polynomial/tests/test_polynomial.py +++ b/numpy/polynomial/tests/test_polynomial.py @@ -1,15 +1,13 @@ """Tests for polynomial module. """ -from __future__ import division, absolute_import, print_function - from functools import reduce import numpy as np import numpy.polynomial.polynomial as poly from numpy.testing import ( assert_almost_equal, assert_raises, assert_equal, assert_, - assert_warns, assert_array_equal) + assert_warns, assert_array_equal, assert_raises_regex) def trim(x): @@ -29,7 +27,7 @@ T9 = [0, 9, 0, -120, 0, 432, 0, -576, 0, 256] Tlist = [T0, T1, T2, T3, T4, T5, T6, T7, T8, T9] -class TestConstants(object): +class TestConstants: def test_polydomain(self): assert_equal(poly.polydomain, [-1, 1]) @@ -44,12 +42,12 @@ class TestConstants(object): assert_equal(poly.polyx, [0, 1]) -class TestArithmetic(object): +class TestArithmetic: def test_polyadd(self): for i in range(5): for j in range(5): - msg = "At i=%d, j=%d" % (i, j) + msg = f"At i={i}, j={j}" tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] += 1 @@ -59,7 +57,7 @@ class TestArithmetic(object): def test_polysub(self): for i in range(5): for j in range(5): - msg = "At i=%d, j=%d" % (i, j) + msg = f"At i={i}, j={j}" tgt = np.zeros(max(i, j) + 1) tgt[i] += 1 tgt[j] -= 1 @@ -77,7 +75,7 @@ class TestArithmetic(object): def test_polymul(self): for i in range(5): for j in range(5): - msg = "At i=%d, j=%d" % (i, j) + msg = f"At i={i}, j={j}" tgt = np.zeros(i + j + 1) tgt[i + j] += 1 res = poly.polymul([0]*i + [1], [0]*j + [1]) @@ -96,7 +94,7 @@ class TestArithmetic(object): # check rest. for i in range(5): for j in range(5): - msg = "At i=%d, j=%d" % (i, j) + msg = f"At i={i}, j={j}" ci = [0]*i + [1, 2] cj = [0]*j + [1, 2] tgt = poly.polyadd(ci, cj) @@ -107,14 +105,14 @@ class TestArithmetic(object): def test_polypow(self): for i in range(5): for j in range(5): - msg = "At i=%d, j=%d" % (i, j) + msg = f"At i={i}, j={j}" c = np.arange(i + 1) tgt = reduce(poly.polymul, [c]*j, np.array([1])) res = poly.polypow(c, j) assert_equal(trim(res), trim(tgt), err_msg=msg) -class TestEvaluation(object): +class TestEvaluation: # coefficients of 1 + 2*x + 3*x**2 c1d = np.array([1., 2., 3.]) c2d = np.einsum('i,j->ij', c1d, c1d) @@ -229,7 +227,8 @@ class TestEvaluation(object): y1, y2, y3 = self.y #test exceptions - assert_raises(ValueError, poly.polyval2d, x1, x2[:2], self.c2d) + assert_raises_regex(ValueError, 'incompatible', + poly.polyval2d, x1, x2[:2], self.c2d) #test values tgt = y1*y2 @@ -246,7 +245,8 @@ class TestEvaluation(object): y1, y2, y3 = self.y #test exceptions - assert_raises(ValueError, poly.polyval3d, x1, x2, x3[:2], self.c3d) + assert_raises_regex(ValueError, 'incompatible', + poly.polyval3d, x1, x2, x3[:2], self.c3d) #test values tgt = y1*y2*y3 @@ -287,7 +287,7 @@ class TestEvaluation(object): assert_(res.shape == (2, 3)*3) -class TestIntegral(object): +class TestIntegral: def test_polyint(self): # check exceptions @@ -386,7 +386,7 @@ class TestIntegral(object): assert_almost_equal(res, tgt) -class TestDerivative(object): +class TestDerivative: def test_polyder(self): # check exceptions @@ -426,7 +426,7 @@ class TestDerivative(object): assert_almost_equal(res, tgt) -class TestVander(object): +class TestVander: # some random values in [-1, 1) x = np.random.random((3, 5))*2 - 1 @@ -474,7 +474,7 @@ class TestVander(object): assert_(van.shape == (1, 5, 24)) -class TestCompanion(object): +class TestCompanion: def test_raises(self): assert_raises(ValueError, poly.polycompanion, []) @@ -489,7 +489,7 @@ class TestCompanion(object): assert_(poly.polycompanion([1, 2])[0, 0] == -.5) -class TestMisc(object): +class TestMisc: def test_polyfromroots(self): res = poly.polyfromroots([]) |