diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-12-10 19:41:33 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-12-10 19:41:33 -0700 |
commit | bb959e1857c3ba2ad98ab87f13fdcc6b43740ffb (patch) | |
tree | 788cdd7c020394c453de5e325846be124aaf7690 | |
parent | 1579ba490d5bc67f16d5311a0789cdf69d81ea11 (diff) | |
download | numpy-bb959e1857c3ba2ad98ab87f13fdcc6b43740ffb.tar.gz |
MAINT: Replace assert with assert_(...) in some tests.
-rw-r--r-- | numpy/core/tests/test_datetime.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_defchararray.py | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_deprecations.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_mem_overlap.py | 9 | ||||
-rw-r--r-- | numpy/core/tests/test_memmap.py | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 30 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_scalarinherit.py | 12 | ||||
-rw-r--r-- | numpy/core/tests/test_shape_base.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 6 | ||||
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 4 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 32 |
13 files changed, 68 insertions, 67 deletions
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index 5fa281867..563aa48fb 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -571,9 +571,9 @@ class TestDateTime(TestCase): "Verify that datetime dtype __setstate__ can handle bad arguments" dt = np.dtype('>M8[us]') assert_raises(ValueError, dt.__setstate__, (4, '>', None, None, None, -1, -1, 0, 1)) - assert (dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2]) + assert_(dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2]) assert_raises(TypeError, dt.__setstate__, (4, '>', None, None, None, -1, -1, 0, ({}, 'xxx'))) - assert (dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2]) + assert_(dt.__reduce__()[2] == np.dtype('>M8[us]').__reduce__()[2]) def test_dtype_promotion(self): # datetime <op> datetime computes the metadata gcd diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py index 9ef316481..e828b879f 100644 --- a/numpy/core/tests/test_defchararray.py +++ b/numpy/core/tests/test_defchararray.py @@ -680,15 +680,15 @@ class TestOperations(TestCase): dtype='S4').view(np.chararray) sl1 = arr[:] assert_array_equal(sl1, arr) - assert sl1.base is arr - assert sl1.base.base is arr.base + assert_(sl1.base is arr) + assert_(sl1.base.base is arr.base) sl2 = arr[:, :] assert_array_equal(sl2, arr) - assert sl2.base is arr - assert sl2.base.base is arr.base + assert_(sl2.base is arr) + assert_(sl2.base.base is arr.base) - assert arr[0, 0] == asbytes('abc') + assert_(arr[0, 0] == asbytes('abc')) def test_empty_indexing(): diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py index 8f7e55d91..518b367f0 100644 --- a/numpy/core/tests/test_deprecations.py +++ b/numpy/core/tests/test_deprecations.py @@ -277,7 +277,7 @@ class TestComparisonDeprecations(_DeprecationTestCase): with warnings.catch_warnings() as l: warnings.filterwarnings("always") assert_raises(TypeError, f, arg1, arg2) - assert not l + assert_(not l) else: # py2 assert_warns(DeprecationWarning, f, arg1, arg2) diff --git a/numpy/core/tests/test_mem_overlap.py b/numpy/core/tests/test_mem_overlap.py index 8d39fa4c0..a8b29ecd1 100644 --- a/numpy/core/tests/test_mem_overlap.py +++ b/numpy/core/tests/test_mem_overlap.py @@ -79,7 +79,8 @@ def _check_assignment(srcidx, dstidx): cpy[dstidx] = arr[srcidx] arr[dstidx] = arr[srcidx] - assert np.all(arr == cpy), 'assigning arr[%s] = arr[%s]' % (dstidx, srcidx) + assert_(np.all(arr == cpy), + 'assigning arr[%s] = arr[%s]' % (dstidx, srcidx)) def test_overlapping_assignments(): @@ -129,7 +130,7 @@ def test_diophantine_fuzz(): if X is None: # Check the simplified decision problem agrees X_simplified = solve_diophantine(A, U, b, simplify=1) - assert X_simplified is None, (A, U, b, X_simplified) + assert_(X_simplified is None, (A, U, b, X_simplified)) # Check no solution exists (provided the problem is # small enough so that brute force checking doesn't @@ -149,7 +150,7 @@ def test_diophantine_fuzz(): else: # Check the simplified decision problem agrees X_simplified = solve_diophantine(A, U, b, simplify=1) - assert X_simplified is not None, (A, U, b, X_simplified) + assert_(X_simplified is not None, (A, U, b, X_simplified)) # Check validity assert_(sum(a*x for a, x in zip(A, X)) == b) @@ -391,7 +392,7 @@ def test_internal_overlap_slices(): s1 = tuple(random_slice(p, s) for p, s in zip(x.shape, steps)) a = x[s1].transpose(t1) - assert not internal_overlap(a) + assert_(not internal_overlap(a)) cases += 1 diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index 1585586ca..e41758c51 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -103,28 +103,28 @@ class TestMemmap(TestCase): shape=self.shape) tmp = (fp + 10) if isinstance(tmp, memmap): - assert tmp._mmap is not fp._mmap + assert_(tmp._mmap is not fp._mmap) def test_indexing_drops_references(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+', shape=self.shape) tmp = fp[[(1, 2), (2, 3)]] if isinstance(tmp, memmap): - assert tmp._mmap is not fp._mmap + assert_(tmp._mmap is not fp._mmap) def test_slicing_keeps_references(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+', shape=self.shape) - assert fp[:2, :2]._mmap is fp._mmap + assert_(fp[:2, :2]._mmap is fp._mmap) def test_view(self): fp = memmap(self.tmpfp, dtype=self.dtype, shape=self.shape) new1 = fp.view() new2 = new1.view() - assert(new1.base is fp) - assert(new2.base is fp) + assert_(new1.base is fp) + assert_(new2.base is fp) new_array = asarray(fp) - assert(new_array.base is fp) + assert_(new_array.base is fp) if __name__ == "__main__": run_module_suite() diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 693847273..593607954 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3588,8 +3588,8 @@ class TestFlat(TestCase): self.a.flat[12] = 100.0 except ValueError: testpassed = True - assert testpassed - assert self.a.flat[12] == 12.0 + assert_(testpassed) + assert_(self.a.flat[12] == 12.0) def test_discontiguous(self): testpassed = False @@ -3597,8 +3597,8 @@ class TestFlat(TestCase): self.b.flat[4] = 100.0 except ValueError: testpassed = True - assert testpassed - assert self.b.flat[4] == 12.0 + assert_(testpassed) + assert_(self.b.flat[4] == 12.0) def test___array__(self): c = self.a.flat.__array__() @@ -3606,16 +3606,16 @@ class TestFlat(TestCase): e = self.a0.flat.__array__() f = self.b0.flat.__array__() - assert c.flags.writeable is False - assert d.flags.writeable is False - assert e.flags.writeable is True - assert f.flags.writeable is True + assert_(c.flags.writeable is False) + assert_(d.flags.writeable is False) + assert_(e.flags.writeable is True) + assert_(f.flags.writeable is True) - assert c.flags.updateifcopy is False - assert d.flags.updateifcopy is False - assert e.flags.updateifcopy is False - assert f.flags.updateifcopy is True - assert f.base is self.b0 + assert_(c.flags.updateifcopy is False) + assert_(d.flags.updateifcopy is False) + assert_(e.flags.updateifcopy is False) + assert_(f.flags.updateifcopy is True) + assert_(f.base is self.b0) class TestResize(TestCase): def test_basic(self): @@ -5440,14 +5440,14 @@ class TestNewBufferProtocol(object): if np.ones((10, 1), order="C").flags.f_contiguous: c.strides = (-1, 80, 8) - assert memoryview(c).strides == (800, 80, 8) + assert_(memoryview(c).strides == (800, 80, 8)) # Writing C-contiguous data to a BytesIO buffer should work fd = io.BytesIO() fd.write(c.data) fortran = c.T - assert memoryview(fortran).strides == (8, 80, 800) + assert_(memoryview(fortran).strides == (8, 80, 800)) arr = np.ones((1, 10)) if arr.flags.f_contiguous: diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 43dad42f1..b7e146b5a 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -328,8 +328,8 @@ class TestSeterr(TestCase): def log_err(*args): self.called += 1 extobj_err = args - assert (len(extobj_err) == 2) - assert ("divide" in extobj_err[0]) + assert_(len(extobj_err) == 2) + assert_("divide" in extobj_err[0]) with np.errstate(divide='ignore'): np.seterrobj([20000, 3, log_err]) diff --git a/numpy/core/tests/test_scalarinherit.py b/numpy/core/tests/test_scalarinherit.py index d8fd0acc3..e8cf7fde0 100644 --- a/numpy/core/tests/test_scalarinherit.py +++ b/numpy/core/tests/test_scalarinherit.py @@ -5,7 +5,7 @@ from __future__ import division, absolute_import, print_function import numpy as np -from numpy.testing import TestCase, run_module_suite +from numpy.testing import TestCase, run_module_suite, assert_ class A(object): @@ -26,17 +26,17 @@ class C0(B0): class TestInherit(TestCase): def test_init(self): x = B(1.0) - assert str(x) == '1.0' + assert_(str(x) == '1.0') y = C(2.0) - assert str(y) == '2.0' + assert_(str(y) == '2.0') z = D(3.0) - assert str(z) == '3.0' + assert_(str(z) == '3.0') def test_init2(self): x = B0(1.0) - assert str(x) == '1.0' + assert_(str(x) == '1.0') y = C0(2.0) - assert str(y) == '2.0' + assert_(str(y) == '2.0') if __name__ == "__main__": run_module_suite() diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index cba083875..0d163c1dc 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -295,8 +295,8 @@ def test_stack(): for axis, expected_shape in zip(axes, expected_shapes): assert_equal(np.stack(arrays, axis).shape, expected_shape) # empty arrays - assert stack([[], [], []]).shape == (3, 0) - assert stack([[], [], []], axis=1).shape == (0, 3) + assert_(stack([[], [], []]).shape == (3, 0)) + assert_(stack([[], [], []], axis=1).shape == (0, 3)) # edge cases assert_raises_regex(ValueError, 'need at least one array', stack, []) assert_raises_regex(ValueError, 'must have the same shape', diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 934d91e7c..eb0985386 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -37,17 +37,17 @@ class TestUfuncKwargs(TestCase): class TestUfunc(TestCase): def test_pickle(self): import pickle - assert pickle.loads(pickle.dumps(np.sin)) is np.sin + 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 + assert_(pickle.loads(pickle.dumps(test_add)) is test_add) def test_pickle_withstring(self): import pickle astring = asbytes("cnumpy.core\n_ufunc_reconstruct\np0\n" "(S'numpy.core.umath'\np1\nS'cos'\np2\ntp3\nRp4\n.") - assert pickle.loads(astring) is np.cos + assert_(pickle.loads(astring) is np.cos) def test_reduceat_shifting_sum(self): L = 6 diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index af904e96a..bffc5c63e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1815,9 +1815,9 @@ M 33 21.99 assert_equal(test.dtype.names, ['f0', 'f1', 'f2']) - assert test.dtype['f0'] == np.float - assert test.dtype['f1'] == np.int64 - assert test.dtype['f2'] == np.integer + assert_(test.dtype['f0'] == np.float) + assert_(test.dtype['f1'] == np.int64) + assert_(test.dtype['f2'] == np.integer) assert_allclose(test['f0'], 73786976294838206464.) assert_equal(test['f1'], 17179869184) diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index afa098f12..fc139be19 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -61,7 +61,7 @@ def get_rtol(dtype): class LinalgCase(object): def __init__(self, name, a, b, exception_cls=None): - assert isinstance(name, str) + assert_(isinstance(name, str)) self.name = name self.a = a self.b = b @@ -267,7 +267,7 @@ def _stride_comb_iter(x): xi = xi[slices] xi[...] = x xi = xi.view(x.__class__) - assert np.all(xi == x) + assert_(np.all(xi == x)) yield xi, "stride_" + "_".join(["%+d" % j for j in repeats]) # generate also zero strides if possible diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index cecdedf26..36b3c5ad0 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -757,46 +757,46 @@ class TestMaskedArray(TestCase): mask = [([False, True, False],)], fill_value = ([999999, 999999, 999999],), dtype = [('a', '<i8', (3,))]) - assert str(t_ma[0]) == "([1, --, 3],)" - assert repr(t_ma[0]) == "([1, --, 3],)" + assert_(str(t_ma[0]) == "([1, --, 3],)") + assert_(repr(t_ma[0]) == "([1, --, 3],)") # additonal tests with structured arrays t_2d = masked_array(data = [([[1, 2], [3,4]],)], mask = [([[False, True], [True, False]],)], dtype = [('a', '<i8', (2,2))]) - assert str(t_2d[0]) == "([[1, --], [--, 4]],)" - assert repr(t_2d[0]) == "([[1, --], [--, 4]],)" + assert_(str(t_2d[0]) == "([[1, --], [--, 4]],)") + assert_(repr(t_2d[0]) == "([[1, --], [--, 4]],)") t_0d = masked_array(data = [(1,2)], mask = [(True,False)], dtype = [('a', '<i8'), ('b', '<i8')]) - assert str(t_0d[0]) == "(--, 2)" - assert repr(t_0d[0]) == "(--, 2)" + assert_(str(t_0d[0]) == "(--, 2)") + assert_(repr(t_0d[0]) == "(--, 2)") t_2d = masked_array(data = [([[1, 2], [3,4]], 1)], mask = [([[False, True], [True, False]], False)], dtype = [('a', '<i8', (2,2)), ('b', float)]) - assert str(t_2d[0]) == "([[1, --], [--, 4]], 1.0)" - assert repr(t_2d[0]) == "([[1, --], [--, 4]], 1.0)" + assert_(str(t_2d[0]) == "([[1, --], [--, 4]], 1.0)") + assert_(repr(t_2d[0]) == "([[1, --], [--, 4]], 1.0)") t_ne = masked_array(data=[(1, (1, 1))], mask=[(True, (True, False))], dtype = [('a', '<i8'), ('b', 'i4,i4')]) - assert str(t_ne[0]) == "(--, (--, 1))" - assert repr(t_ne[0]) == "(--, (--, 1))" + assert_(str(t_ne[0]) == "(--, (--, 1))") + assert_(repr(t_ne[0]) == "(--, (--, 1))") def test_object_with_array(self): mx1 = masked_array([1.], mask=[True]) mx2 = masked_array([1., 2.]) mx = masked_array([mx1, mx2], mask=[False, True]) - assert mx[0] is mx1 - assert mx[1] is not mx2 - assert np.all(mx[1].data == mx2.data) - assert np.all(mx[1].mask) + assert_(mx[0] is mx1) + assert_(mx[1] is not mx2) + assert_(np.all(mx[1].data == mx2.data)) + assert_(np.all(mx[1].mask)) # check that we return a view. mx[1].data[0] = 0. - assert mx2[0] == 0. + assert_(mx2[0] == 0.) class TestMaskedArrayArithmetic(TestCase): @@ -4254,7 +4254,7 @@ def test_append_masked_array_along_axis(): def test_default_fill_value_complex(): # regression test for Python 3, where 'unicode' was not defined - assert default_fill_value(1 + 1j) == 1.e20 + 0.0j + assert_(default_fill_value(1 + 1j) == 1.e20 + 0.0j) ############################################################################### if __name__ == "__main__": |