summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2011-04-05 21:00:10 -0600
committerCharles Harris <charlesr.harris@gmail.com>2011-04-05 21:02:29 -0600
commit966038e30b21e62ab7729527f3f0bba6e18eb805 (patch)
tree084bd7b40be49614b3770657ceaf1b539adbf964 /numpy/lib
parent4cb2eb4df95740661d7f1944451d2c1cb3482bcf (diff)
downloadnumpy-966038e30b21e62ab7729527f3f0bba6e18eb805.tar.gz
STY: Replace assert by assert_ in tests. There remain 124 uses of
assert in non-testing files that should be checked for correctness.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/tests/test__iotools.py4
-rw-r--r--numpy/lib/tests/test_arrayterator.py11
-rw-r--r--numpy/lib/tests/test_format.py2
-rw-r--r--numpy/lib/tests/test_index_tricks.py20
-rw-r--r--numpy/lib/tests/test_io.py16
-rw-r--r--numpy/lib/tests/test_polynomial.py16
-rw-r--r--numpy/lib/tests/test_recfunctions.py4
-rw-r--r--numpy/lib/tests/test_shape_base.py10
-rw-r--r--numpy/lib/tests/test_stride_tricks.py2
-rw-r--r--numpy/lib/tests/test_type_check.py60
-rw-r--r--numpy/lib/tests/test_utils.py10
11 files changed, 78 insertions, 77 deletions
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py
index 853d06087..a0f1546e2 100644
--- a/numpy/lib/tests/test__iotools.py
+++ b/numpy/lib/tests/test__iotools.py
@@ -125,7 +125,7 @@ class TestNameValidator(TestCase):
"Test validate no names"
namelist = None
validator = NameValidator()
- assert(validator(namelist) is None)
+ assert_(validator(namelist) is None)
assert_equal(validator(namelist, nbfields=3), ['f0', 'f1', 'f2'])
@@ -191,7 +191,7 @@ class TestStringConverter(TestCase):
"Make sure that string-to-object functions are properly recognized"
conv = StringConverter(_bytes_to_date)
assert_equal(conv._mapper[-2][0](0), 0j)
- assert(hasattr(conv, 'default'))
+ assert_(hasattr(conv, 'default'))
#
def test_keep_default(self):
"Make sure we don't lose an explicit default"
diff --git a/numpy/lib/tests/test_arrayterator.py b/numpy/lib/tests/test_arrayterator.py
index 3dce009d3..c1c59ba31 100644
--- a/numpy/lib/tests/test_arrayterator.py
+++ b/numpy/lib/tests/test_arrayterator.py
@@ -3,6 +3,7 @@ from operator import mul
import numpy as np
from numpy.random import randint
from numpy.lib import Arrayterator
+from numpy.testing import assert_
import sys
if sys.version_info[0] >= 3:
@@ -23,10 +24,10 @@ def test():
# Check that each block has at most ``buf_size`` elements
for block in b:
- assert len(block.flat) <= (buf_size or els)
+ assert_(len(block.flat) <= (buf_size or els))
# Check that all elements are iterated correctly
- assert list(b.flat) == list(a.flat)
+ assert_(list(b.flat) == list(a.flat))
# Slice arrayterator
start = [randint(dim) for dim in shape]
@@ -38,13 +39,13 @@ def test():
# Check that each block has at most ``buf_size`` elements
for block in c:
- assert len(block.flat) <= (buf_size or els)
+ assert_(len(block.flat) <= (buf_size or els))
# Check that the arrayterator is sliced correctly
- assert np.all(c.__array__() == d)
+ assert_(np.all(c.__array__() == d))
# Check that all elements are iterated correctly
- assert list(c.flat) == list(d.flat)
+ assert_(list(c.flat) == list(d.flat))
if __name__ == '__main__':
from numpy.testing import run_module_suite
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index ff8e93704..76fc81397 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -421,7 +421,7 @@ def roundtrip(arr):
return arr2
def assert_equal(o1, o2):
- assert o1 == o2
+ assert_(o1 == o2)
def test_roundtrip():
diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py
index 8b42292a2..f0190937b 100644
--- a/numpy/lib/tests/test_index_tricks.py
+++ b/numpy/lib/tests/test_index_tricks.py
@@ -72,11 +72,11 @@ class TestGrid(TestCase):
def test_basic(self):
a = mgrid[-1:1:10j]
b = mgrid[-1:1:0.1]
- assert(a.shape == (10,))
- assert(b.shape == (20,))
- assert(a[0] == -1)
+ assert_(a.shape == (10,))
+ assert_(b.shape == (20,))
+ assert_(a[0] == -1)
assert_almost_equal(a[-1],1)
- assert(b[0] == -1)
+ assert_(b[0] == -1)
assert_almost_equal(b[1]-b[0],0.1,11)
assert_almost_equal(b[-1],b[0]+19*0.1,11)
assert_almost_equal(a[1]-a[0],2.0/9.0,11)
@@ -89,8 +89,8 @@ class TestGrid(TestCase):
def test_nd(self):
c = mgrid[-1:1:10j,-2:2:10j]
d = mgrid[-1:1:0.1,-2:2:0.2]
- assert(c.shape == (2,10,10))
- assert(d.shape == (2,20,20))
+ assert_(c.shape == (2,10,10))
+ assert_(d.shape == (2,20,20))
assert_array_equal(c[0][0,:],-ones(10,'d'))
assert_array_equal(c[1][:,0],-2*ones(10,'d'))
assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11)
@@ -108,21 +108,21 @@ class TestConcatenator(TestCase):
def test_mixed_type(self):
g = r_[10.1, 1:10]
- assert(g.dtype == 'f8')
+ assert_(g.dtype == 'f8')
def test_more_mixed_type(self):
g = r_[-10.1, array([1]), array([2,3,4]), 10.0]
- assert(g.dtype == 'f8')
+ assert_(g.dtype == 'f8')
def test_2d(self):
b = rand(5,5)
c = rand(5,5)
d = r_['1',b,c] # append columns
- assert(d.shape == (5,10))
+ assert_(d.shape == (5,10))
assert_array_equal(d[:,:5],b)
assert_array_equal(d[:,5:],c)
d = r_[b,c]
- assert(d.shape == (10,5))
+ assert_(d.shape == (10,5))
assert_array_equal(d[:5,:],b)
assert_array_equal(d[5:,:],c)
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 4894f8939..8d4c8f179 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1393,21 +1393,21 @@ def test_npzfile_dict():
z = np.load(s)
- assert 'x' in z
- assert 'y' in z
- assert 'x' in z.keys()
- assert 'y' in z.keys()
+ assert_('x' in z)
+ assert_('y' in z)
+ assert_('x' in z.keys())
+ assert_('y' in z.keys())
for f, a in z.iteritems():
- assert f in ['x', 'y']
+ assert_(f in ['x', 'y'])
assert_equal(a.shape, (3, 3))
- assert len(z.items()) == 2
+ assert_(len(z.items()) == 2)
for f in z:
- assert f in ['x', 'y']
+ assert_(f in ['x', 'y'])
- assert 'x' in list(z.iterkeys())
+ assert_('x' in list(z.iterkeys()))
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py
index 2dbffa0b8..8c3a6d62b 100644
--- a/numpy/lib/tests/test_polynomial.py
+++ b/numpy/lib/tests/test_polynomial.py
@@ -117,25 +117,25 @@ class TestDocs(TestCase):
from decimal import Decimal
p = np.poly1d([Decimal('4.0'), Decimal('3.0'), Decimal('2.0')])
p2 = p * Decimal('1.333333333333333')
- assert p2[1] == Decimal("3.9999999999999990")
+ assert_(p2[1] == Decimal("3.9999999999999990"))
p2 = p.deriv()
- assert p2[1] == Decimal('8.0')
+ assert_(p2[1] == Decimal('8.0'))
p2 = p.integ()
- assert p2[3] == Decimal("1.333333333333333333333333333")
- assert p2[2] == Decimal('1.5')
- assert np.issubdtype(p2.coeffs.dtype, np.object_)
+ assert_(p2[3] == Decimal("1.333333333333333333333333333"))
+ assert_(p2[2] == Decimal('1.5'))
+ assert_(np.issubdtype(p2.coeffs.dtype, np.object_))
def test_complex(self):
p = np.poly1d([3j, 2j, 1j])
p2 = p.integ()
- assert (p2.coeffs == [1j,1j,1j,0]).all()
+ assert_((p2.coeffs == [1j,1j,1j,0]).all())
p2 = p.deriv()
- assert (p2.coeffs == [6j,2j]).all()
+ assert_((p2.coeffs == [6j,2j]).all())
def test_integ_coeffs(self):
p = np.poly1d([3,2,1])
p2 = p.integ(3, k=[9,7,6])
- assert (p2.coeffs == [1/4./5.,1/3./4.,1/2./3.,9/1./2.,7,6]).all()
+ assert_((p2.coeffs == [1/4./5.,1/3./4.,1/2./3.,9/1./2.,7,6]).all())
def test_zero_dims(self):
try:
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 14af43a59..57d977814 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -81,7 +81,7 @@ class TestRecFunctions(TestCase):
assert_equal(test, control)
#
test = drop_fields(a, ['a', 'b'])
- assert(test is None)
+ assert_(test is None)
def test_rename_fields(self):
@@ -308,7 +308,7 @@ class TestMergeArrays(TestCase):
assert_equal(test, control)
test = merge_arrays((x, mx), usemask=True, asrecarray=True)
assert_equal(test, control)
- assert(isinstance(test, MaskedRecords))
+ assert_(isinstance(test, MaskedRecords))
#
def test_w_singlefield(self):
"Test single field"
diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py
index 403761e93..9d6cd0551 100644
--- a/numpy/lib/tests/test_shape_base.py
+++ b/numpy/lib/tests/test_shape_base.py
@@ -30,7 +30,7 @@ class TestArraySplit(TestCase):
a = arange(10)
try:
res = array_split(a,0)
- assert(0) # it should have thrown a value error
+ assert_(0) # it should have thrown a value error
except ValueError:
pass
@@ -149,7 +149,7 @@ class TestSplit(TestCase):
a = arange(10)
try:
res = split(a,3)
- assert(0) # should raise an error
+ assert_(0) # should raise an error
except ValueError:
pass
@@ -189,7 +189,7 @@ class TestHsplit(TestCase):
a= array(1)
try:
hsplit(a,2)
- assert(0)
+ assert_(0)
except ValueError:
pass
@@ -214,7 +214,7 @@ class TestVsplit(TestCase):
a= array([1,2,3,4])
try:
vsplit(a,2)
- assert(0)
+ assert_(0)
except ValueError:
pass
@@ -234,7 +234,7 @@ class TestDsplit(TestCase):
[1,2,3,4]])
try:
dsplit(a,2)
- assert(0)
+ assert_(0)
except ValueError:
pass
diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py
index 8f0ac52b8..d7cf114f7 100644
--- a/numpy/lib/tests/test_stride_tricks.py
+++ b/numpy/lib/tests/test_stride_tricks.py
@@ -11,7 +11,7 @@ def assert_shapes_correct(input_shapes, expected_shape):
outarrays = broadcast_arrays(*inarrays)
outshapes = [a.shape for a in outarrays]
expected = [expected_shape] * len(inarrays)
- assert outshapes == expected
+ assert_(outshapes == expected)
def assert_incompatible_shapes_raise(input_shapes):
""" Broadcast a list of arrays with the given (incompatible) input shapes
diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py
index 30b25c42f..c8bc87c6e 100644
--- a/numpy/lib/tests/test_type_check.py
+++ b/numpy/lib/tests/test_type_check.py
@@ -3,15 +3,15 @@ from numpy.lib import *
from numpy.core import *
from numpy.compat import asbytes
-try:
- import ctypes
- _HAS_CTYPE = True
-except ImportError:
- _HAS_CTYPE = False
+try:
+ import ctypes
+ _HAS_CTYPE = True
+except ImportError:
+ _HAS_CTYPE = False
+
-
def assert_all(x):
- assert(all(x)), x
+ assert_(all(x), x)
class TestCommonType(TestCase):
@@ -21,10 +21,10 @@ class TestCommonType(TestCase):
af64 = array([[1,2],[3,4]], dtype=float64)
acs = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=csingle)
acd = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=cdouble)
- assert common_type(af32) == float32
- assert common_type(af64) == float64
- assert common_type(acs) == csingle
- assert common_type(acd) == cdouble
+ assert_(common_type(af32) == float32)
+ assert_(common_type(af64) == float64)
+ assert_(common_type(acs) == csingle)
+ assert_(common_type(acd) == cdouble)
@@ -81,12 +81,12 @@ class TestMintypecode(TestCase):
class TestIsscalar(TestCase):
def test_basic(self):
- assert(isscalar(3))
- assert(not isscalar([3]))
- assert(not isscalar((3,)))
- assert(isscalar(3j))
- assert(isscalar(10L))
- assert(isscalar(4.0))
+ assert_(isscalar(3))
+ assert_(not isscalar([3]))
+ assert_(not isscalar((3,)))
+ assert_(isscalar(3j))
+ assert_(isscalar(10L))
+ assert_(isscalar(4.0))
class TestReal(TestCase):
@@ -116,7 +116,7 @@ class TestIscomplex(TestCase):
def test_fail(self):
z = array([-1,0,1])
res = iscomplex(z)
- assert(not sometrue(res,axis=0))
+ assert_(not sometrue(res,axis=0))
def test_pass(self):
z = array([-1j,1,0])
res = iscomplex(z)
@@ -139,18 +139,18 @@ class TestIscomplexobj(TestCase):
def test_basic(self):
z = array([-1,0,1])
- assert(not iscomplexobj(z))
+ assert_(not iscomplexobj(z))
z = array([-1j,0,-1])
- assert(iscomplexobj(z))
+ assert_(iscomplexobj(z))
class TestIsrealobj(TestCase):
def test_basic(self):
z = array([-1,0,1])
- assert(isrealobj(z))
+ assert_(isrealobj(z))
z = array([-1j,0,-1])
- assert(not isrealobj(z))
+ assert_(not isrealobj(z))
class TestIsnan(TestCase):
@@ -298,9 +298,9 @@ class TestIsposinf(TestCase):
vals = isposinf(array((-1.,0,1))/0.)
finally:
seterr(**olderr)
- assert(vals[0] == 0)
- assert(vals[1] == 0)
- assert(vals[2] == 1)
+ assert_(vals[0] == 0)
+ assert_(vals[1] == 0)
+ assert_(vals[2] == 1)
class TestIsneginf(TestCase):
@@ -310,9 +310,9 @@ class TestIsneginf(TestCase):
vals = isneginf(array((-1.,0,1))/0.)
finally:
seterr(**olderr)
- assert(vals[0] == 1)
- assert(vals[1] == 0)
- assert(vals[2] == 0)
+ assert_(vals[0] == 1)
+ assert_(vals[1] == 0)
+ assert_(vals[2] == 0)
class TestNanToNum(TestCase):
@@ -324,7 +324,7 @@ class TestNanToNum(TestCase):
finally:
seterr(**olderr)
assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))
- assert(vals[1] == 0)
+ assert_(vals[1] == 0)
assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))
def test_integer(self):
@@ -380,7 +380,7 @@ class TestArrayConversion(TestCase):
def test_asfarray(self):
a = asfarray(array([1,2,3]))
assert_equal(a.__class__,ndarray)
- assert issubdtype(a.dtype,float)
+ assert_(issubdtype(a.dtype,float))
class TestDateTimeData(object):
diff --git a/numpy/lib/tests/test_utils.py b/numpy/lib/tests/test_utils.py
index 6a09c6dbd..80f90f04b 100644
--- a/numpy/lib/tests/test_utils.py
+++ b/numpy/lib/tests/test_utils.py
@@ -9,7 +9,7 @@ def test_lookfor():
utils.lookfor('eigenvalue', module='numpy', output=out,
import_modules=False)
out = out.getvalue()
- assert 'numpy.linalg.eig' in out
+ assert_('numpy.linalg.eig' in out)
@deprecate
@@ -25,14 +25,14 @@ def old_func3(self, x):
new_func3 = deprecate(old_func3, old_name="old_func3", new_name="new_func3")
def test_deprecate_decorator():
- assert 'deprecated' in old_func.__doc__
+ assert_('deprecated' in old_func.__doc__)
def test_deprecate_decorator_message():
- assert 'Rather use new_func2' in old_func2.__doc__
+ assert_('Rather use new_func2' in old_func2.__doc__)
def test_deprecate_fn():
- assert 'old_func3' in new_func3.__doc__
- assert 'new_func3' in new_func3.__doc__
+ assert_('old_func3' in new_func3.__doc__)
+ assert_('new_func3' in new_func3.__doc__)
if __name__ == "__main__":
run_module_suite()