summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/test_datetime.py52
-rw-r--r--numpy/core/tests/test_defchararray.py150
-rw-r--r--numpy/core/tests/test_errstate.py6
-rw-r--r--numpy/core/tests/test_function_base.py16
-rw-r--r--numpy/core/tests/test_multiarray.py36
-rw-r--r--numpy/core/tests/test_numerictypes.py16
-rw-r--r--numpy/core/tests/test_regression.py118
-rw-r--r--numpy/core/tests/test_scalarmath.py6
-rw-r--r--numpy/core/tests/test_shape_base.py16
-rw-r--r--numpy/core/tests/test_ufunc.py8
-rw-r--r--numpy/core/tests/test_umath.py112
-rw-r--r--numpy/distutils/tests/test_fcompiler_gnu.py8
-rw-r--r--numpy/distutils/tests/test_misc_util.py4
-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
-rw-r--r--numpy/linalg/tests/test_linalg.py16
-rw-r--r--numpy/ma/tests/test_core.py16
-rw-r--r--numpy/ma/tests/test_extras.py4
-rw-r--r--numpy/ma/tests/test_mrecords.py10
-rw-r--r--numpy/ma/tests/test_old_ma.py226
-rw-r--r--numpy/ma/testutils.py5
-rw-r--r--numpy/matrixlib/tests/test_defmatrix.py148
-rw-r--r--numpy/matrixlib/tests/test_multiarray.py4
-rw-r--r--numpy/matrixlib/tests/test_regression.py8
-rw-r--r--numpy/testing/nosetester.py8
-rw-r--r--numpy/testing/utils.py7
35 files changed, 579 insertions, 576 deletions
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 9cbfde134..97fb1151f 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -8,56 +8,56 @@ class TestDateTime(TestCase):
'h', 'm', 's', 'ms', 'us',
'ns', 'ps', 'fs', 'as']:
dt1 = np.dtype('M8[750%s]'%unit)
- assert dt1 == np.dtype('datetime64[750%s]' % unit)
+ assert_(dt1 == np.dtype('datetime64[750%s]' % unit))
dt2 = np.dtype('m8[%s]' % unit)
- assert dt2 == np.dtype('timedelta64[%s]' % unit)
+ assert_(dt2 == np.dtype('timedelta64[%s]' % unit))
def test_hours(self):
t = np.ones(3, dtype='M8[s]')
t[0] = 60*60*24 + 60*60*10
- assert t[0].item().hour == 10
+ assert_(t[0].item().hour == 10 )
def test_divisor_conversion_year(self):
- assert np.dtype('M8[Y/4]') == np.dtype('M8[3M]')
- assert np.dtype('M8[Y/13]') == np.dtype('M8[4W]')
- assert np.dtype('M8[3Y/73]') == np.dtype('M8[15D]')
+ assert_(np.dtype('M8[Y/4]') == np.dtype('M8[3M]'))
+ assert_(np.dtype('M8[Y/13]') == np.dtype('M8[4W]'))
+ assert_(np.dtype('M8[3Y/73]') == np.dtype('M8[15D]'))
def test_divisor_conversion_month(self):
- assert np.dtype('M8[M/2]') == np.dtype('M8[2W]')
- assert np.dtype('M8[M/15]') == np.dtype('M8[2D]')
- assert np.dtype('M8[3M/40]') == np.dtype('M8[54h]')
+ assert_(np.dtype('M8[M/2]') == np.dtype('M8[2W]'))
+ assert_(np.dtype('M8[M/15]') == np.dtype('M8[2D]'))
+ assert_(np.dtype('M8[3M/40]') == np.dtype('M8[54h]'))
def test_divisor_conversion_week(self):
- assert np.dtype('m8[W/5]') == np.dtype('m8[B]')
- assert np.dtype('m8[W/7]') == np.dtype('m8[D]')
- assert np.dtype('m8[3W/14]') == np.dtype('m8[36h]')
- assert np.dtype('m8[5W/140]') == np.dtype('m8[360m]')
+ assert_(np.dtype('m8[W/5]') == np.dtype('m8[B]'))
+ assert_(np.dtype('m8[W/7]') == np.dtype('m8[D]'))
+ assert_(np.dtype('m8[3W/14]') == np.dtype('m8[36h]'))
+ assert_(np.dtype('m8[5W/140]') == np.dtype('m8[360m]'))
def test_divisor_conversion_bday(self):
- assert np.dtype('M8[B/12]') == np.dtype('M8[2h]')
- assert np.dtype('M8[B/120]') == np.dtype('M8[12m]')
- assert np.dtype('M8[3B/960]') == np.dtype('M8[270s]')
+ assert_(np.dtype('M8[B/12]') == np.dtype('M8[2h]'))
+ assert_(np.dtype('M8[B/120]') == np.dtype('M8[12m]'))
+ assert_(np.dtype('M8[3B/960]') == np.dtype('M8[270s]'))
def test_divisor_conversion_day(self):
- assert np.dtype('M8[D/12]') == np.dtype('M8[2h]')
- assert np.dtype('M8[D/120]') == np.dtype('M8[12m]')
- assert np.dtype('M8[3D/960]') == np.dtype('M8[270s]')
+ assert_(np.dtype('M8[D/12]') == np.dtype('M8[2h]'))
+ assert_(np.dtype('M8[D/120]') == np.dtype('M8[12m]'))
+ assert_(np.dtype('M8[3D/960]') == np.dtype('M8[270s]'))
def test_divisor_conversion_hour(self):
- assert np.dtype('m8[h/30]') == np.dtype('m8[2m]')
- assert np.dtype('m8[3h/300]') == np.dtype('m8[36s]')
+ assert_(np.dtype('m8[h/30]') == np.dtype('m8[2m]'))
+ assert_(np.dtype('m8[3h/300]') == np.dtype('m8[36s]'))
def test_divisor_conversion_minute(self):
- assert np.dtype('m8[m/30]') == np.dtype('m8[2s]')
- assert np.dtype('m8[3m/300]') == np.dtype('m8[600ms]')
+ assert_(np.dtype('m8[m/30]') == np.dtype('m8[2s]'))
+ assert_(np.dtype('m8[3m/300]') == np.dtype('m8[600ms]'))
def test_divisor_conversion_second(self):
- assert np.dtype('m8[s/100]') == np.dtype('m8[10ms]')
- assert np.dtype('m8[3s/10000]') == np.dtype('m8[300us]')
+ assert_(np.dtype('m8[s/100]') == np.dtype('m8[10ms]'))
+ assert_(np.dtype('m8[3s/10000]') == np.dtype('m8[300us]'))
def test_divisor_conversion_fs(self):
- assert np.dtype('M8[fs/100]') == np.dtype('M8[10as]')
+ assert_(np.dtype('M8[fs/100]') == np.dtype('M8[10as]'))
self.assertRaises(ValueError, lambda : np.dtype('M8[3fs/10000]'))
def test_divisor_conversion_as(self):
diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py
index d4df9ae6f..2ff95ec81 100644
--- a/numpy/core/tests/test_defchararray.py
+++ b/numpy/core/tests/test_defchararray.py
@@ -36,13 +36,13 @@ class TestBasic(TestCase):
assert_equal(B.dtype, A.dtype)
assert_equal(B.shape, A.shape)
B[0,0] = 'changed'
- assert B[0,0] != A[0,0]
+ assert_(B[0,0] != A[0,0])
C = np.char.asarray(A)
assert_array_equal(C, A)
assert_equal(C.dtype, A.dtype)
C[0,0] = 'changed again'
- assert C[0,0] != B[0,0]
- assert C[0,0] == A[0,0]
+ assert_(C[0,0] != B[0,0])
+ assert_(C[0,0] == A[0,0])
def test_from_unicode_array(self):
A = np.array([['abc', u'Sigma \u03a3'],
@@ -63,20 +63,20 @@ class TestBasic(TestCase):
def test_unicode_upconvert(self):
A = np.char.array(['abc'])
B = np.char.array([u'\u03a3'])
- assert issubclass((A + B).dtype.type, np.unicode_)
+ assert_(issubclass((A + B).dtype.type, np.unicode_))
def test_from_string(self):
A = np.char.array(asbytes('abc'))
assert_equal(len(A), 1)
assert_equal(len(A[0]), 3)
- assert issubclass(A.dtype.type, np.string_)
+ assert_(issubclass(A.dtype.type, np.string_))
def test_from_unicode(self):
A = np.char.array(u'\u03a3')
assert_equal(len(A), 1)
assert_equal(len(A[0]), 1)
assert_equal(A.itemsize, 4)
- assert issubclass(A.dtype.type, np.unicode_)
+ assert_(issubclass(A.dtype.type, np.unicode_))
class TestVecString(TestCase):
def test_non_existent_method(self):
@@ -123,12 +123,12 @@ class TestWhitespace(TestCase):
['789', 'xyz']]).view(np.chararray)
def test1(self):
- assert all(self.A == self.B)
- assert all(self.A >= self.B)
- assert all(self.A <= self.B)
- assert all(negative(self.A > self.B))
- assert all(negative(self.A < self.B))
- assert all(negative(self.A != self.B))
+ assert_(all(self.A == self.B))
+ assert_(all(self.A >= self.B))
+ assert_(all(self.A <= self.B))
+ assert_(all(negative(self.A > self.B)))
+ assert_(all(negative(self.A < self.B)))
+ assert_(all(negative(self.A != self.B)))
class TestChar(TestCase):
def setUp(self):
@@ -189,12 +189,12 @@ class TestInformation(TestCase):
[u'123 \t 345 \0 ', u'UPPER']]).view(np.chararray)
def test_len(self):
- assert issubclass(np.char.str_len(self.A).dtype.type, np.integer)
+ assert_(issubclass(np.char.str_len(self.A).dtype.type, np.integer))
assert_array_equal(np.char.str_len(self.A), [[5, 0], [5, 9], [12, 5]])
assert_array_equal(np.char.str_len(self.B), [[3, 0], [5, 9], [12, 5]])
def test_count(self):
- assert issubclass(self.A.count('').dtype.type, np.integer)
+ assert_(issubclass(self.A.count('').dtype.type, np.integer))
assert_array_equal(self.A.count('a'), [[1, 0], [0, 1], [0, 0]])
assert_array_equal(self.A.count('123'), [[0, 0], [1, 0], [1, 0]])
# Python doesn't seem to like counting NULL characters
@@ -205,7 +205,7 @@ class TestInformation(TestCase):
# assert_array_equal(self.B.count('\0'), [[0, 0], [0, 0], [1, 0]])
def test_endswith(self):
- assert issubclass(self.A.endswith('').dtype.type, np.bool_)
+ assert_(issubclass(self.A.endswith('').dtype.type, np.bool_))
assert_array_equal(self.A.endswith(' '), [[1, 0], [0, 0], [1, 0]])
assert_array_equal(self.A.endswith('3', 0, 3), [[0, 0], [1, 0], [1, 0]])
def fail():
@@ -213,7 +213,7 @@ class TestInformation(TestCase):
self.assertRaises(TypeError, fail)
def test_find(self):
- assert issubclass(self.A.find('a').dtype.type, np.integer)
+ assert_(issubclass(self.A.find('a').dtype.type, np.integer))
assert_array_equal(self.A.find('a'), [[1, -1], [-1, 6], [-1, -1]])
assert_array_equal(self.A.find('3'), [[-1, -1], [2, -1], [2, -1]])
assert_array_equal(self.A.find('a', 0, 2), [[1, -1], [-1, -1], [-1, -1]])
@@ -223,39 +223,39 @@ class TestInformation(TestCase):
def fail():
self.A.index('a')
self.assertRaises(ValueError, fail)
- assert np.char.index('abcba', 'b') == 1
- assert issubclass(np.char.index('abcba', 'b').dtype.type, np.integer)
+ assert_(np.char.index('abcba', 'b') == 1)
+ assert_(issubclass(np.char.index('abcba', 'b').dtype.type, np.integer))
def test_isalnum(self):
- assert issubclass(self.A.isalnum().dtype.type, np.bool_)
+ assert_(issubclass(self.A.isalnum().dtype.type, np.bool_))
assert_array_equal(self.A.isalnum(), [[False, False], [True, True], [False, True]])
def test_isalpha(self):
- assert issubclass(self.A.isalpha().dtype.type, np.bool_)
+ assert_(issubclass(self.A.isalpha().dtype.type, np.bool_))
assert_array_equal(self.A.isalpha(), [[False, False], [False, True], [False, True]])
def test_isdigit(self):
- assert issubclass(self.A.isdigit().dtype.type, np.bool_)
+ assert_(issubclass(self.A.isdigit().dtype.type, np.bool_))
assert_array_equal(self.A.isdigit(), [[False, False], [True, False], [False, False]])
def test_islower(self):
- assert issubclass(self.A.islower().dtype.type, np.bool_)
+ assert_(issubclass(self.A.islower().dtype.type, np.bool_))
assert_array_equal(self.A.islower(), [[True, False], [False, False], [False, False]])
def test_isspace(self):
- assert issubclass(self.A.isspace().dtype.type, np.bool_)
+ assert_(issubclass(self.A.isspace().dtype.type, np.bool_))
assert_array_equal(self.A.isspace(), [[False, False], [False, False], [False, False]])
def test_istitle(self):
- assert issubclass(self.A.istitle().dtype.type, np.bool_)
+ assert_(issubclass(self.A.istitle().dtype.type, np.bool_))
assert_array_equal(self.A.istitle(), [[False, False], [False, False], [False, False]])
def test_isupper(self):
- assert issubclass(self.A.isupper().dtype.type, np.bool_)
+ assert_(issubclass(self.A.isupper().dtype.type, np.bool_))
assert_array_equal(self.A.isupper(), [[False, False], [False, False], [False, True]])
def test_rfind(self):
- assert issubclass(self.A.rfind('a').dtype.type, np.integer)
+ assert_(issubclass(self.A.rfind('a').dtype.type, np.integer))
assert_array_equal(self.A.rfind('a'), [[1, -1], [-1, 6], [-1, -1]])
assert_array_equal(self.A.rfind('3'), [[-1, -1], [2, -1], [6, -1]])
assert_array_equal(self.A.rfind('a', 0, 2), [[1, -1], [-1, -1], [-1, -1]])
@@ -265,11 +265,11 @@ class TestInformation(TestCase):
def fail():
self.A.rindex('a')
self.assertRaises(ValueError, fail)
- assert np.char.rindex('abcba', 'b') == 3
- assert issubclass(np.char.rindex('abcba', 'b').dtype.type, np.integer)
+ assert_(np.char.rindex('abcba', 'b') == 3)
+ assert_(issubclass(np.char.rindex('abcba', 'b').dtype.type, np.integer))
def test_startswith(self):
- assert issubclass(self.A.startswith('').dtype.type, np.bool_)
+ assert_(issubclass(self.A.startswith('').dtype.type, np.bool_))
assert_array_equal(self.A.startswith(' '), [[1, 0], [0, 0], [0, 0]])
assert_array_equal(self.A.startswith('1', 0, 3), [[0, 0], [1, 0], [1, 0]])
def fail():
@@ -288,27 +288,27 @@ class TestMethods(TestCase):
[u'123 \t 345 \0 ', u'UPPER']]).view(np.chararray)
def test_capitalize(self):
- assert issubclass(self.A.capitalize().dtype.type, np.string_)
+ assert_(issubclass(self.A.capitalize().dtype.type, np.string_))
assert_array_equal(self.A.capitalize(), asbytes_nested([
[' abc ', ''],
['12345', 'Mixedcase'],
['123 \t 345 \0 ', 'Upper']]))
- assert issubclass(self.B.capitalize().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.capitalize().dtype.type, np.unicode_))
assert_array_equal(self.B.capitalize(), [
[u' \u03c3 ', ''],
['12345', 'Mixedcase'],
['123 \t 345 \0 ', 'Upper']])
def test_center(self):
- assert issubclass(self.A.center(10).dtype.type, np.string_)
+ assert_(issubclass(self.A.center(10).dtype.type, np.string_))
widths = np.array([[10, 20]])
C = self.A.center([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
C = self.A.center(20, asbytes('#'))
- assert np.all(C.startswith(asbytes('#')))
- assert np.all(C.endswith(asbytes('#')))
+ assert_(np.all(C.startswith(asbytes('#'))))
+ assert_(np.all(C.endswith(asbytes('#'))))
C = np.char.center(asbytes('FOO'), [[10, 20], [15, 8]])
- assert issubclass(C.dtype.type, np.string_)
+ assert_(issubclass(C.dtype.type, np.string_))
assert_array_equal(C, asbytes_nested([
[' FOO ', ' FOO '],
[' FOO ', ' FOO ']]))
@@ -316,18 +316,18 @@ class TestMethods(TestCase):
def test_decode(self):
if sys.version_info[0] >= 3:
A = np.char.array([asbytes('\\u03a3')])
- assert A.decode('unicode-escape')[0] == '\u03a3'
+ assert_(A.decode('unicode-escape')[0] == '\u03a3')
else:
A = np.char.array(['736563726574206d657373616765'])
- assert A.decode('hex_codec')[0] == 'secret message'
+ assert_(A.decode('hex_codec')[0] == 'secret message')
def test_encode(self):
B = self.B.encode('unicode_escape')
- assert B[0][0] == asbytes(r' \u03a3 ')
+ assert_(B[0][0] == asbytes(r' \u03a3 '))
def test_expandtabs(self):
T = self.A.expandtabs()
- assert T[2][0] == asbytes('123 345')
+ assert_(T[2][0] == asbytes('123 345'))
def test_join(self):
if sys.version_info[0] >= 3:
@@ -339,9 +339,9 @@ class TestMethods(TestCase):
A = np.char.join([',', '#'], A0)
if sys.version_info[0] >= 3:
- assert issubclass(A.dtype.type, np.unicode_)
+ assert_(issubclass(A.dtype.type, np.unicode_))
else:
- assert issubclass(A.dtype.type, np.string_)
+ assert_(issubclass(A.dtype.type, np.string_))
assert_array_equal(np.char.join([',', '#'], A0),
[
[' ,a,b,c, ', ''],
@@ -349,34 +349,34 @@ class TestMethods(TestCase):
['1,2,3, ,\t, ,3,4,5, ,\x00, ', 'U#P#P#E#R']])
def test_ljust(self):
- assert issubclass(self.A.ljust(10).dtype.type, np.string_)
+ assert_(issubclass(self.A.ljust(10).dtype.type, np.string_))
widths = np.array([[10, 20]])
C = self.A.ljust([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
C = self.A.ljust(20, asbytes('#'))
assert_array_equal(C.startswith(asbytes('#')), [
[False, True], [False, False], [False, False]])
- assert np.all(C.endswith(asbytes('#')))
+ assert_(np.all(C.endswith(asbytes('#'))))
C = np.char.ljust(asbytes('FOO'), [[10, 20], [15, 8]])
- assert issubclass(C.dtype.type, np.string_)
+ assert_(issubclass(C.dtype.type, np.string_))
assert_array_equal(C, asbytes_nested([
['FOO ', 'FOO '],
['FOO ', 'FOO ']]))
def test_lower(self):
- assert issubclass(self.A.lower().dtype.type, np.string_)
+ assert_(issubclass(self.A.lower().dtype.type, np.string_))
assert_array_equal(self.A.lower(), asbytes_nested([
[' abc ', ''],
['12345', 'mixedcase'],
['123 \t 345 \0 ', 'upper']]))
- assert issubclass(self.B.lower().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.lower().dtype.type, np.unicode_))
assert_array_equal(self.B.lower(), [
[u' \u03c3 ', u''],
[u'12345', u'mixedcase'],
[u'123 \t 345 \0 ', u'upper']])
def test_lstrip(self):
- assert issubclass(self.A.lstrip().dtype.type, np.string_)
+ assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
assert_array_equal(self.A.lstrip(), asbytes_nested([
['abc ', ''],
['12345', 'MixedCase'],
@@ -386,7 +386,7 @@ class TestMethods(TestCase):
[' abc', ''],
['2345', 'ixedCase'],
['23 \t 345 \x00', 'UPPER']]))
- assert issubclass(self.B.lstrip().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.lstrip(), [
[u'\u03a3 ', ''],
['12345', 'MixedCase'],
@@ -395,7 +395,7 @@ class TestMethods(TestCase):
def test_partition(self):
if sys.version_info >= (2, 5):
P = self.A.partition(asbytes_nested(['3', 'M']))
- assert issubclass(P.dtype.type, np.string_)
+ assert_(issubclass(P.dtype.type, np.string_))
assert_array_equal(P, asbytes_nested([
[(' abc ', '', ''), ('', '', '')],
[('12', '3', '45'), ('', 'M', 'ixedCase')],
@@ -404,7 +404,7 @@ class TestMethods(TestCase):
def test_replace(self):
R = self.A.replace(asbytes_nested(['3', 'a']),
asbytes_nested(['##########', '@']))
- assert issubclass(R.dtype.type, np.string_)
+ assert_(issubclass(R.dtype.type, np.string_))
assert_array_equal(R, asbytes_nested([
[' abc ', ''],
['12##########45', 'MixedC@se'],
@@ -413,23 +413,23 @@ class TestMethods(TestCase):
if sys.version_info[0] < 3:
# NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
R = self.A.replace(asbytes('a'), u'\u03a3')
- assert issubclass(R.dtype.type, np.unicode_)
+ assert_(issubclass(R.dtype.type, np.unicode_))
assert_array_equal(R, [
[u' \u03a3bc ', ''],
['12345', u'MixedC\u03a3se'],
['123 \t 345 \x00', 'UPPER']])
def test_rjust(self):
- assert issubclass(self.A.rjust(10).dtype.type, np.string_)
+ assert_(issubclass(self.A.rjust(10).dtype.type, np.string_))
widths = np.array([[10, 20]])
C = self.A.rjust([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
C = self.A.rjust(20, asbytes('#'))
- assert np.all(C.startswith(asbytes('#')))
+ assert_(np.all(C.startswith(asbytes('#'))))
assert_array_equal(C.endswith(asbytes('#')),
[[False, True], [False, False], [False, False]])
C = np.char.rjust(asbytes('FOO'), [[10, 20], [15, 8]])
- assert issubclass(C.dtype.type, np.string_)
+ assert_(issubclass(C.dtype.type, np.string_))
assert_array_equal(C, asbytes_nested([
[' FOO', ' FOO'],
[' FOO', ' FOO']]))
@@ -437,7 +437,7 @@ class TestMethods(TestCase):
def test_rpartition(self):
if sys.version_info >= (2, 5):
P = self.A.rpartition(asbytes_nested(['3', 'M']))
- assert issubclass(P.dtype.type, np.string_)
+ assert_(issubclass(P.dtype.type, np.string_))
assert_array_equal(P, asbytes_nested([
[('', '', ' abc '), ('', '', '')],
[('12', '3', '45'), ('', 'M', 'ixedCase')],
@@ -445,14 +445,14 @@ class TestMethods(TestCase):
def test_rsplit(self):
A = self.A.rsplit(asbytes('3'))
- assert issubclass(A.dtype.type, np.object_)
+ assert_(issubclass(A.dtype.type, np.object_))
assert_equal(A.tolist(), asbytes_nested([
[[' abc '], ['']],
[['12', '45'], ['MixedCase']],
[['12', ' \t ', '45 \x00 '], ['UPPER']]]))
def test_rstrip(self):
- assert issubclass(self.A.rstrip().dtype.type, np.string_)
+ assert_(issubclass(self.A.rstrip().dtype.type, np.string_))
assert_array_equal(self.A.rstrip(), asbytes_nested([
[' abc', ''],
['12345', 'MixedCase'],
@@ -462,14 +462,14 @@ class TestMethods(TestCase):
[' abc ', ''],
['1234', 'MixedCase'],
['123 \t 345 \x00', 'UPP']]))
- assert issubclass(self.B.rstrip().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.rstrip(), [
[u' \u03a3', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']])
def test_strip(self):
- assert issubclass(self.A.strip().dtype.type, np.string_)
+ assert_(issubclass(self.A.strip().dtype.type, np.string_))
assert_array_equal(self.A.strip(), asbytes_nested([
['abc', ''],
['12345', 'MixedCase'],
@@ -479,7 +479,7 @@ class TestMethods(TestCase):
[' abc ', ''],
['234', 'ixedCas'],
['23 \t 345 \x00', 'UPP']]))
- assert issubclass(self.B.strip().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
assert_array_equal(self.B.strip(), [
[u'\u03a3', ''],
['12345', 'MixedCase'],
@@ -487,7 +487,7 @@ class TestMethods(TestCase):
def test_split(self):
A = self.A.split(asbytes('3'))
- assert issubclass(A.dtype.type, np.object_)
+ assert_(issubclass(A.dtype.type, np.object_))
assert_equal(A.tolist(), asbytes_nested([
[[' abc '], ['']],
[['12', '45'], ['MixedCase']],
@@ -495,41 +495,41 @@ class TestMethods(TestCase):
def test_splitlines(self):
A = np.char.array(['abc\nfds\nwer']).splitlines()
- assert issubclass(A.dtype.type, np.object_)
- assert A.shape == (1,)
- assert len(A[0]) == 3
+ assert_(issubclass(A.dtype.type, np.object_))
+ assert_(A.shape == (1,))
+ assert_(len(A[0]) == 3)
def test_swapcase(self):
- assert issubclass(self.A.swapcase().dtype.type, np.string_)
+ assert_(issubclass(self.A.swapcase().dtype.type, np.string_))
assert_array_equal(self.A.swapcase(), asbytes_nested([
[' ABC ', ''],
['12345', 'mIXEDcASE'],
['123 \t 345 \0 ', 'upper']]))
- assert issubclass(self.B.swapcase().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.swapcase().dtype.type, np.unicode_))
assert_array_equal(self.B.swapcase(), [
[u' \u03c3 ', u''],
[u'12345', u'mIXEDcASE'],
[u'123 \t 345 \0 ', u'upper']])
def test_title(self):
- assert issubclass(self.A.title().dtype.type, np.string_)
+ assert_(issubclass(self.A.title().dtype.type, np.string_))
assert_array_equal(self.A.title(), asbytes_nested([
[' Abc ', ''],
['12345', 'Mixedcase'],
['123 \t 345 \0 ', 'Upper']]))
- assert issubclass(self.B.title().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.title().dtype.type, np.unicode_))
assert_array_equal(self.B.title(), [
[u' \u03a3 ', u''],
[u'12345', u'Mixedcase'],
[u'123 \t 345 \0 ', u'Upper']])
def test_upper(self):
- assert issubclass(self.A.upper().dtype.type, np.string_)
+ assert_(issubclass(self.A.upper().dtype.type, np.string_))
assert_array_equal(self.A.upper(), asbytes_nested([
[' ABC ', ''],
['12345', 'MIXEDCASE'],
['123 \t 345 \0 ', 'UPPER']]))
- assert issubclass(self.B.upper().dtype.type, np.unicode_)
+ assert_(issubclass(self.B.upper().dtype.type, np.unicode_))
assert_array_equal(self.B.upper(), [
[u' \u03a3 ', u''],
[u'12345', u'MIXEDCASE'],
@@ -539,7 +539,7 @@ class TestMethods(TestCase):
def fail():
self.A.isnumeric()
self.assertRaises(TypeError, fail)
- assert issubclass(self.B.isnumeric().dtype.type, np.bool_)
+ assert_(issubclass(self.B.isnumeric().dtype.type, np.bool_))
assert_array_equal(self.B.isnumeric(), [
[False, False], [True, False], [False, False]])
@@ -547,7 +547,7 @@ class TestMethods(TestCase):
def fail():
self.A.isdecimal()
self.assertRaises(TypeError, fail)
- assert issubclass(self.B.isdecimal().dtype.type, np.bool_)
+ assert_(issubclass(self.B.isdecimal().dtype.type, np.bool_))
assert_array_equal(self.B.isdecimal(), [
[False, False], [True, False], [False, False]])
@@ -563,7 +563,7 @@ class TestOperations(TestCase):
AB = np.array([['abcefg', '123456'],
['789051', 'xyztuv']]).view(np.chararray)
assert_array_equal(AB, (self.A + self.B))
- assert len((self.A + self.B)[0][0]) == 6
+ assert_(len((self.A + self.B)[0][0]) == 6)
def test_radd(self):
QA = np.array([['qabc', 'q123'],
@@ -617,8 +617,8 @@ class TestOperations(TestCase):
assert_array_equal(A2, (A % [[1,2],[3,4]]))
def test_rmod(self):
- assert ("%s" % self.A) == str(self.A)
- assert ("%r" % self.A) == repr(self.A)
+ assert_(("%s" % self.A) == str(self.A))
+ assert_(("%r" % self.A) == repr(self.A))
for ob in [42, object()]:
try:
diff --git a/numpy/core/tests/test_errstate.py b/numpy/core/tests/test_errstate.py
index 732bb3e93..a9588463b 100644
--- a/numpy/core/tests/test_errstate.py
+++ b/numpy/core/tests/test_errstate.py
@@ -46,10 +46,10 @@ class TestErrstate(TestCase):
print(args)
olderrcall = geterrcall()
with errstate(call=foo):
- assert(geterrcall() is foo), 'call is not foo'
+ assert_(geterrcall() is foo, 'call is not foo')
with errstate(call=None):
- assert(geterrcall() is None), 'call is not None'
- assert(geterrcall() is olderrcall), 'call is not olderrcall'
+ assert_(geterrcall() is None, 'call is not None')
+ assert_(geterrcall() is olderrcall, 'call is not olderrcall')
"""
diff --git a/numpy/core/tests/test_function_base.py b/numpy/core/tests/test_function_base.py
index 67ce8953f..f1a08d9d5 100644
--- a/numpy/core/tests/test_function_base.py
+++ b/numpy/core/tests/test_function_base.py
@@ -5,28 +5,28 @@ from numpy import logspace, linspace
class TestLogspace(TestCase):
def test_basic(self):
y = logspace(0,6)
- assert(len(y)==50)
+ assert_(len(y)==50)
y = logspace(0,6,num=100)
- assert(y[-1] == 10**6)
+ assert_(y[-1] == 10**6)
y = logspace(0,6,endpoint=0)
- assert(y[-1] < 10**6)
+ assert_(y[-1] < 10**6)
y = logspace(0,6,num=7)
assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])
class TestLinspace(TestCase):
def test_basic(self):
y = linspace(0,10)
- assert(len(y)==50)
+ assert_(len(y)==50)
y = linspace(2,10,num=100)
- assert(y[-1] == 10)
+ assert_(y[-1] == 10)
y = linspace(2,10,endpoint=0)
- assert(y[-1] < 10)
+ assert_(y[-1] < 10)
def test_corner(self):
y = list(linspace(0,1,1))
- assert y == [0.0], y
+ assert_(y == [0.0], y)
y = list(linspace(0,1,2.5))
- assert y == [0.0, 1.0]
+ assert_(y == [0.0, 1.0])
def test_type(self):
t1 = linspace(0,1,0).dtype
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index fc51f8cb3..f0d50aa24 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -930,7 +930,7 @@ class TestArgmax(TestCase):
aargmax = a.argmax(i)
axes = range(a.ndim)
axes.remove(i)
- assert all(amax == aargmax.choose(*a.transpose(i,*axes)))
+ assert_(all(amax == aargmax.choose(*a.transpose(i,*axes))))
def test_combinations(self):
for arr, pos in self.nan_arr:
@@ -961,8 +961,8 @@ class TestNewaxis(TestCase):
class TestClip(TestCase):
def _check_range(self,x,cmin,cmax):
- assert np.all(x >= cmin)
- assert np.all(x <= cmax)
+ assert_(np.all(x >= cmin))
+ assert_(np.all(x <= cmax))
def _clip_type(self,type_group,array_max,
clip_min,clip_max,inplace=False,
@@ -1013,18 +1013,18 @@ class TestClip(TestCase):
def test_max_or_min(self):
val = np.array([0,1,2,3,4,5,6,7])
x = val.clip(3)
- assert np.all(x >= 3)
+ assert_(np.all(x >= 3))
x = val.clip(min=3)
- assert np.all(x >= 3)
+ assert_(np.all(x >= 3))
x = val.clip(max=4)
- assert np.all(x <= 4)
+ assert_(np.all(x <= 4))
class TestPutmask(object):
def tst_basic(self,x,T,mask,val):
np.putmask(x,mask,val)
- assert np.all(x[mask] == T(val))
- assert x.dtype == T
+ assert_(np.all(x[mask] == T(val)))
+ assert_(x.dtype == T)
def test_ip_types(self):
unchecked_types = [str, unicode, np.void, object]
@@ -1114,7 +1114,7 @@ class TestTake(object):
rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
dtype=[('x', '<f8'), ('y', '>f8'), ('z', '<f8')])
rec1 = rec.take([1])
- assert rec1['x'] == 5.0 and rec1['y'] == 4.0
+ assert_(rec1['x'] == 5.0 and rec1['y'] == 4.0)
class TestLexsort(TestCase):
@@ -1492,11 +1492,11 @@ class TestStats(TestCase):
self.info = getattr(obj, "info", '')
dat = TestArray([[1,2,3,4],[5,6,7,8]], 'jubba')
res = dat.mean(1)
- assert res.info == dat.info
+ assert_(res.info == dat.info)
res = dat.std(1)
- assert res.info == dat.info
+ assert_(res.info == dat.info)
res = dat.var(1)
- assert res.info == dat.info
+ assert_(res.info == dat.info)
class TestDot(TestCase):
def test_dot_2args(self):
@@ -1565,20 +1565,20 @@ class TestSummarization(TestCase):
def test_1d(self):
A = np.arange(1001)
strA = '[ 0 1 2 ..., 998 999 1000]'
- assert str(A) == strA
+ assert_(str(A) == strA)
reprA = 'array([ 0, 1, 2, ..., 998, 999, 1000])'
- assert repr(A) == reprA
+ assert_(repr(A) == reprA)
def test_2d(self):
A = np.arange(1002).reshape(2,501)
strA = '[[ 0 1 2 ..., 498 499 500]\n' \
' [ 501 502 503 ..., 999 1000 1001]]'
- assert str(A) == strA
+ assert_(str(A) == strA)
reprA = 'array([[ 0, 1, 2, ..., 498, 499, 500],\n' \
' [ 501, 502, 503, ..., 999, 1000, 1001]])'
- assert repr(A) == reprA
+ assert_(repr(A) == reprA)
class TestChoose(TestCase):
@@ -1976,8 +1976,8 @@ if sys.version_info >= (2, 6):
x = memoryview(obj)
y = np.asarray(x)
y2 = np.array(x)
- assert not y.flags.owndata
- assert y2.flags.owndata
+ assert_(not y.flags.owndata)
+ assert_(y2.flags.owndata)
assert_equal(y.dtype, obj.dtype)
assert_array_equal(obj, y)
assert_equal(y2.dtype, obj.dtype)
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index bb71ce008..98a6e07aa 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -337,25 +337,25 @@ class TestEmptyField(TestCase):
def test_assign(self):
a = np.arange(10, dtype=np.float32)
a.dtype = [("int", "<0i4"),("float", "<2f4")]
- assert(a['int'].shape == (5,0))
- assert(a['float'].shape == (5,2))
+ assert_(a['int'].shape == (5,0))
+ assert_(a['float'].shape == (5,2))
class TestCommonType(TestCase):
def test_scalar_loses1(self):
res = np.find_common_type(['f4','f4','i2'],['f8'])
- assert(res == 'f4')
+ assert_(res == 'f4')
def test_scalar_loses2(self):
res = np.find_common_type(['f4','f4'],['i8'])
- assert(res == 'f4')
+ assert_(res == 'f4')
def test_scalar_wins(self):
res = np.find_common_type(['f4','f4','i2'],['c8'])
- assert(res == 'c8')
+ assert_(res == 'c8')
def test_scalar_wins2(self):
res = np.find_common_type(['u4','i4','i4'],['f4'])
- assert(res == 'f8')
+ assert_(res == 'f8')
def test_scalar_wins3(self): # doesn't go up to 'f16' on purpose
res = np.find_common_type(['u8','i8','i8'],['f8'])
- assert(res == 'f8')
+ assert_(res == 'f8')
class TestMultipleFields(TestCase):
def setUp(self):
@@ -366,7 +366,7 @@ class TestMultipleFields(TestCase):
self.assertRaises(ValueError, self._bad_call)
def test_return(self):
res = self.ary[['f0','f2']].tolist()
- assert(res == [(1,3), (5,7)])
+ assert_(res == [(1,3), (5,7)])
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 8014628a0..3269b76c2 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -370,9 +370,9 @@ class TestRegression(TestCase):
res1 = getattr(arr, func_meth)()
res2 = getattr(np, func)(arr2)
if res1 is None:
- assert abs(arr-res2).max() < 1e-8, func
+ assert_(abs(arr-res2).max() < 1e-8, func)
else:
- assert abs(res1-res2).max() < 1e-8, func
+ assert_(abs(res1-res2).max() < 1e-8, func)
for func in funcs2:
arr1 = np.random.rand(8,7)
@@ -386,7 +386,7 @@ class TestRegression(TestCase):
if res1 is None:
res1 = getattr(arr1, func)(arr2)
res2 = getattr(np, func)(arr1, arr2)
- assert abs(res1-res2).max() < 1e-8, func
+ assert_(abs(res1-res2).max() < 1e-8, func)
def test_mem_lexsort_strings(self, level=rlevel):
"""Ticket #298"""
@@ -404,7 +404,7 @@ class TestRegression(TestCase):
ra = np.array([(1,2.3)], dtype=dt)
rb = np.rec.array(ra, dtype=dt)
rb['x'] = 2.
- assert ra['x'] != rb['x']
+ assert_(ra['x'] != rb['x'])
def test_rec_fromarray(self, level=rlevel):
"""Ticket #322"""
@@ -435,7 +435,7 @@ class TestRegression(TestCase):
def test_dtype_tuple(self, level=rlevel):
"""Ticket #334"""
- assert np.dtype('i4') == np.dtype(('i4',()))
+ assert_(np.dtype('i4') == np.dtype(('i4',())))
def test_dtype_posttuple(self, level=rlevel):
"""Ticket #335"""
@@ -477,7 +477,7 @@ class TestRegression(TestCase):
def test_object_argmax(self, level=rlevel):
a = np.array([1,2,3],dtype=object)
- assert a.argmax() == 2
+ assert_(a.argmax() == 2)
def test_recarray_fields(self, level=rlevel):
"""Ticket #372"""
@@ -535,7 +535,7 @@ class TestRegression(TestCase):
def test_junk_in_string_fields_of_recarray(self, level=rlevel):
"""Ticket #483"""
r = np.array([[asbytes('abc')]], dtype=[('var1', '|S20')])
- assert asbytes(r['var1'][0][0]) == asbytes('abc')
+ assert_(asbytes(r['var1'][0][0]) == asbytes('abc'))
def test_take_output(self, level=rlevel):
"""Ensure that 'take' honours output parameter."""
@@ -582,7 +582,7 @@ class TestRegression(TestCase):
def test_argmax_byteorder(self, level=rlevel):
"""Ticket #546"""
a = np.arange(3, dtype='>f')
- assert a[a.argmax()] == a.max()
+ assert_(a[a.argmax()] == a.max())
def test_rand_seed(self, level=rlevel):
"""Ticket #555"""
@@ -741,16 +741,16 @@ class TestRegression(TestCase):
arr0 = np.zeros(2, dtype=np.object_)
arr0[0] = a
- assert cnt(a) == cnt0_a + 1
+ assert_(cnt(a) == cnt0_a + 1)
arr0[1] = b
- assert cnt(b) == cnt0_b + 1
+ assert_(cnt(b) == cnt0_b + 1)
arr[:,:] = arr0
- assert cnt(a) == cnt0_a + 6
- assert cnt(b) == cnt0_b + 6
+ assert_(cnt(a) == cnt0_a + 6)
+ assert_(cnt(b) == cnt0_b + 6)
arr[:,0] = None
- assert cnt(a) == cnt0_a + 1
+ assert_(cnt(a) == cnt0_a + 1)
del arr, arr0
@@ -760,20 +760,20 @@ class TestRegression(TestCase):
arr[:,0] = a
arr[:,1] = b
- assert cnt(a) == cnt0_a + 5
- assert cnt(b) == cnt0_b + 5
+ assert_(cnt(a) == cnt0_a + 5)
+ assert_(cnt(b) == cnt0_b + 5)
arr2 = arr.copy()
- assert cnt(a) == cnt0_a + 10
- assert cnt(b) == cnt0_b + 10
+ assert_(cnt(a) == cnt0_a + 10)
+ assert_(cnt(b) == cnt0_b + 10)
arr2 = arr[:,0].copy()
- assert cnt(a) == cnt0_a + 10
- assert cnt(b) == cnt0_b + 5
+ assert_(cnt(a) == cnt0_a + 10)
+ assert_(cnt(b) == cnt0_b + 5)
arr2 = arr.flatten()
- assert cnt(a) == cnt0_a + 10
- assert cnt(b) == cnt0_b + 10
+ assert_(cnt(a) == cnt0_a + 10)
+ assert_(cnt(b) == cnt0_b + 10)
del arr, arr2
@@ -784,23 +784,23 @@ class TestRegression(TestCase):
arr1[...] = a
arr2[...] = b
- assert cnt(a) == cnt0_a + 5
- assert cnt(b) == cnt0_b + 5
+ assert_(cnt(a) == cnt0_a + 5)
+ assert_(cnt(b) == cnt0_b + 5)
arr3 = np.concatenate((arr1, arr2))
- assert cnt(a) == cnt0_a + 5 + 5
- assert cnt(b) == cnt0_b + 5 + 5
+ assert_(cnt(a) == cnt0_a + 5 + 5)
+ assert_(cnt(b) == cnt0_b + 5 + 5)
arr3 = arr1.repeat(3, axis=0)
- assert cnt(a) == cnt0_a + 5 + 3*5
+ assert_(cnt(a) == cnt0_a + 5 + 3*5)
arr3 = arr1.take([1,2,3], axis=0)
- assert cnt(a) == cnt0_a + 5 + 3
+ assert_(cnt(a) == cnt0_a + 5 + 3)
x = np.array([[0],[1],[0],[1],[1]], int)
arr3 = x.choose(arr1, arr2)
- assert cnt(a) == cnt0_a + 5 + 2
- assert cnt(b) == cnt0_b + 5 + 3
+ assert_(cnt(a) == cnt0_a + 5 + 2)
+ assert_(cnt(b) == cnt0_b + 5 + 3)
def test_mem_custom_float_to_array(self, level=rlevel):
"""Ticket 702"""
@@ -822,9 +822,9 @@ class TestRegression(TestCase):
arr[:] = d
del d
arr[:] = arr # refcount of 'd' might hit zero here
- assert not arr[0].deleted
+ assert_(not arr[0].deleted)
arr[:] = arr # trying to induce a segfault by doing it again...
- assert not arr[0].deleted
+ assert_(not arr[0].deleted)
def test_mem_fromiter_invalid_dtype_string(self, level=rlevel):
x = [1,2,3]
@@ -835,7 +835,7 @@ class TestRegression(TestCase):
"""Ticket #713"""
oldsize = np.setbufsize(10*16)
a = np.array([None]*161, object)
- assert not np.any(a)
+ assert_(not np.any(a))
np.setbufsize(oldsize)
def test_mem_0d_array_index(self, level=rlevel):
@@ -894,8 +894,8 @@ class TestRegression(TestCase):
else:
xp = pickle.load(open(filename))
xpd = xp.astype(np.float64)
- assert (xp.__array_interface__['data'][0] !=
- xpd.__array_interface__['data'][0])
+ assert_((xp.__array_interface__['data'][0] !=
+ xpd.__array_interface__['data'][0]))
def test_compress_small_type(self, level=rlevel):
"""Ticket #789, changeset 5217.
@@ -1023,8 +1023,8 @@ class TestRegression(TestCase):
b = list(a.dtype.names)
b[0] = "notfoo"
a.dtype.names = b
- assert a.dtype.names[0] == "notfoo"
- assert a.dtype.names[1] == "bar"
+ assert_(a.dtype.names[0] == "notfoo")
+ assert_(a.dtype.names[1] == "bar")
def test_for_object_scalar_creation(self, level=rlevel):
"""Ticket #816"""
@@ -1033,12 +1033,12 @@ class TestRegression(TestCase):
b2 = np.object_(3.0)
c = np.object_([4,5])
d = np.object_([None, {}, []])
- assert a is None
- assert type(b) is int
- assert type(b2) is float
- assert type(c) is np.ndarray
- assert c.dtype == object
- assert d.dtype == object
+ assert_(a is None)
+ assert_(type(b) is int)
+ assert_(type(b2) is float)
+ assert_(type(c) is np.ndarray)
+ assert_(c.dtype == object)
+ assert_(d.dtype == object)
def test_array_resize_method_system_error(self):
"""Ticket #840 - order should be an invalid keyword."""
@@ -1066,7 +1066,7 @@ class TestRegression(TestCase):
z**p # this shouldn't leak a reference to errobj
gc.collect()
n_after = len(gc.get_objects())
- assert n_before >= n_after, (n_before, n_after)
+ assert_(n_before >= n_after, (n_before, n_after))
finally:
np.seterr(**old_err)
@@ -1075,8 +1075,8 @@ class TestRegression(TestCase):
data = [('john', 4), ('mary', 5)]
dtype1 = [(('source:yy', 'name'), 'O'), (('source:xx', 'id'), int)]
arr = np.array(data, dtype=dtype1)
- assert arr[0][0] == 'john'
- assert arr[0][1] == 4
+ assert_(arr[0][0] == 'john')
+ assert_(arr[0][1] == 4)
def test_blasdot_uninitialized_memory(self):
"""Ticket #950"""
@@ -1091,8 +1091,8 @@ class TestRegression(TestCase):
# `dot` should just return zero (m,n) matrix
z = np.dot(x, y)
- assert np.all(z == 0)
- assert z.shape == (m, n)
+ assert_(np.all(z == 0))
+ assert_(z.shape == (m, n))
def test_zeros(self):
"""Regression test for #1061."""
@@ -1125,8 +1125,8 @@ class TestRegression(TestCase):
"""Ticket #1058"""
a = np.fromiter(range(10), dtype='b')
b = np.fromiter(range(10), dtype='B')
- assert np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9]))
- assert np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9]))
+ assert_(np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9])))
+ assert_(np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9])))
def test_array_from_sequence_scalar_array(self):
"""Ticket #1078: segfaults when creating an array with a sequence of 0d
@@ -1189,15 +1189,15 @@ class TestRegression(TestCase):
def test_mixed_string_unicode_array_creation(self):
a = np.array(['1234', u'123'])
- assert a.itemsize == 16
+ assert_(a.itemsize == 16)
a = np.array([u'123', '1234'])
- assert a.itemsize == 16
+ assert_(a.itemsize == 16)
a = np.array(['1234', u'123', '12345'])
- assert a.itemsize == 20
+ assert_(a.itemsize == 20)
a = np.array([u'123', '1234', u'12345'])
- assert a.itemsize == 20
+ assert_(a.itemsize == 20)
a = np.array([u'123', '1234', u'1234'])
- assert a.itemsize == 16
+ assert_(a.itemsize == 16)
def test_misaligned_objects_segfault(self):
"""Ticket #1198 and #1267"""
@@ -1246,7 +1246,7 @@ class TestRegression(TestCase):
strb = 'bbbb'
x = np.array([[(0,stra),(1,strb)]], 'i8,O')
x[x.nonzero()] = x.ravel()[:1]
- assert x[0,1] == x[0,0]
+ assert_(x[0,1] == x[0,0])
def test_structured_arrays_with_objects2(self):
"""Ticket #1299 second test"""
@@ -1256,8 +1256,8 @@ class TestRegression(TestCase):
numa = sys.getrefcount(stra)
x = np.array([[(0,stra),(1,strb)]], 'i8,O')
x[x.nonzero()] = x.ravel()[:1]
- assert sys.getrefcount(strb) == numb
- assert sys.getrefcount(stra) == numa + 2
+ assert_(sys.getrefcount(strb) == numb)
+ assert_(sys.getrefcount(stra) == numa + 2)
def test_duplicate_title_and_name(self):
"""Ticket #1254"""
@@ -1304,8 +1304,8 @@ class TestRegression(TestCase):
def test_fromiter_comparison(self, level=rlevel):
a = np.fromiter(range(10), dtype='b')
b = np.fromiter(range(10), dtype='B')
- assert np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9]))
- assert np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9]))
+ assert_(np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9])))
+ assert_(np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9])))
def test_fromstring_crash(self):
# Ticket #1345: the following should not cause a crash
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index b00164525..24b5eae24 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -13,7 +13,7 @@ class TestTypes(TestCase):
def test_types(self, level=1):
for atype in types:
a = atype(1)
- assert a == 1, "error with %r: got %r" % (atype,a)
+ assert_(a == 1, "error with %r: got %r" % (atype,a))
def test_type_add(self, level=1):
# list of types
@@ -47,7 +47,7 @@ class TestPower(TestCase):
for t in [np.int8, np.int16]:
a = t(3)
b = a ** 4
- assert b == 81, "error with %r: got %r" % (t,b)
+ assert_(b == 81, "error with %r: got %r" % (t,b))
def test_large_types(self):
for t in [np.int32, np.int64, np.float32, np.float64, np.longdouble]:
@@ -55,7 +55,7 @@ class TestPower(TestCase):
b = a ** 4
msg = "error with %r: got %r" % (t,b)
if np.issubdtype(t, np.integer):
- assert b == 6765201, msg
+ assert_(b == 6765201, msg)
else:
assert_almost_equal(b, 6765201, err_msg=msg)
diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py
index 48b7e3763..f282dbe25 100644
--- a/numpy/core/tests/test_shape_base.py
+++ b/numpy/core/tests/test_shape_base.py
@@ -31,11 +31,11 @@ class TestAtleast1d(TestCase):
def test_r1array(self):
""" Test to make sure equivalent Travis O's r1array function
"""
- assert(atleast_1d(3).shape == (1,))
- assert(atleast_1d(3j).shape == (1,))
- assert(atleast_1d(3L).shape == (1,))
- assert(atleast_1d(3.0).shape == (1,))
- assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))
+ assert_(atleast_1d(3).shape == (1,))
+ assert_(atleast_1d(3j).shape == (1,))
+ assert_(atleast_1d(3L).shape == (1,))
+ assert_(atleast_1d(3.0).shape == (1,))
+ assert_(atleast_1d([[2,3],[4,5]]).shape == (2,2))
class TestAtleast2d(TestCase):
def test_0D_array(self):
@@ -66,9 +66,9 @@ class TestAtleast2d(TestCase):
def test_r2array(self):
""" Test to make sure equivalent Travis O's r2array function
"""
- assert(atleast_2d(3).shape == (1,1))
- assert(atleast_2d([3j,1]).shape == (1,2))
- assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))
+ assert_(atleast_2d(3).shape == (1,1))
+ assert_(atleast_2d([3j,1]).shape == (1,2))
+ assert_(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))
class TestAtleast3d(TestCase):
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 070ae42f2..c75b2d385 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -128,24 +128,24 @@ class TestUfunc(TestCase):
# check unary PyUFunc_O_O
msg = "PyUFunc_O_O"
x = np.ones(10, dtype=np.object)[0::2]
- assert np.all(np.abs(x) == 1), msg
+ assert_(np.all(np.abs(x) == 1), msg)
# check unary PyUFunc_O_O_method
msg = "PyUFunc_O_O_method"
x = np.zeros(10, dtype=np.object)[0::2]
for i in range(len(x)) :
x[i] = foo()
- assert np.all(np.logical_not(x) == True), msg
+ assert_(np.all(np.logical_not(x) == True), msg)
# check binary PyUFunc_OO_O
msg = "PyUFunc_OO_O"
x = np.ones(10, dtype=np.object)[0::2]
- assert np.all(np.add(x,x) == 2), msg
+ assert_(np.all(np.add(x,x) == 2), msg)
# check binary PyUFunc_OO_O_method
msg = "PyUFunc_OO_O_method"
x = np.zeros(10, dtype=np.object)[0::2]
for i in range(len(x)) :
x[i] = foo()
- assert np.all(np.logical_and(x,x) == 1), msg
+ assert_(np.all(np.logical_and(x,x) == 1), msg)
# check PyUFunc_On_Om
# fixme -- I don't know how to do this yet
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 32dda95cf..9c5ff8eef 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -187,11 +187,11 @@ class TestLogAddExp2(object):
np.seterr(**err)
def test_nan(self):
- assert np.isnan(np.logaddexp2(np.nan, np.inf))
- assert np.isnan(np.logaddexp2(np.inf, np.nan))
- assert np.isnan(np.logaddexp2(np.nan, 0))
- assert np.isnan(np.logaddexp2(0, np.nan))
- assert np.isnan(np.logaddexp2(np.nan, np.nan))
+ assert_(np.isnan(np.logaddexp2(np.nan, np.inf)))
+ assert_(np.isnan(np.logaddexp2(np.inf, np.nan)))
+ assert_(np.isnan(np.logaddexp2(np.nan, 0)))
+ assert_(np.isnan(np.logaddexp2(0, np.nan)))
+ assert_(np.isnan(np.logaddexp2(np.nan, np.nan)))
class TestLog(TestCase):
@@ -253,11 +253,11 @@ class TestLogAddExp(object):
np.seterr(**err)
def test_nan(self):
- assert np.isnan(np.logaddexp(np.nan, np.inf))
- assert np.isnan(np.logaddexp(np.inf, np.nan))
- assert np.isnan(np.logaddexp(np.nan, 0))
- assert np.isnan(np.logaddexp(0, np.nan))
- assert np.isnan(np.logaddexp(np.nan, np.nan))
+ assert_(np.isnan(np.logaddexp(np.nan, np.inf)))
+ assert_(np.isnan(np.logaddexp(np.inf, np.nan)))
+ assert_(np.isnan(np.logaddexp(np.nan, 0)))
+ assert_(np.isnan(np.logaddexp(0, np.nan)))
+ assert_(np.isnan(np.logaddexp(np.nan, np.nan)))
class TestLog1p(TestCase):
@@ -281,7 +281,7 @@ class TestHypot(TestCase, object):
def assert_hypot_isnan(x, y):
err = np.seterr(invalid='ignore')
try:
- assert np.isnan(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not nan" % (x, y, ncu.hypot(x, y))
+ assert_(np.isnan(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not nan" % (x, y, ncu.hypot(x, y)))
finally:
np.seterr(**err)
@@ -289,7 +289,7 @@ def assert_hypot_isnan(x, y):
def assert_hypot_isinf(x, y):
err = np.seterr(invalid='ignore')
try:
- assert np.isinf(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not inf" % (x, y, ncu.hypot(x, y))
+ assert_(np.isinf(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not inf" % (x, y, ncu.hypot(x, y)))
finally:
np.seterr(**err)
@@ -307,23 +307,23 @@ class TestHypotSpecialValues(TestCase):
def assert_arctan2_isnan(x, y):
- assert np.isnan(ncu.arctan2(x, y)), "arctan(%s, %s) is %s, not nan" % (x, y, ncu.arctan2(x, y))
+ assert_(np.isnan(ncu.arctan2(x, y)), "arctan(%s, %s) is %s, not nan" % (x, y, ncu.arctan2(x, y)))
def assert_arctan2_ispinf(x, y):
- assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) > 0), "arctan(%s, %s) is %s, not +inf" % (x, y, ncu.arctan2(x, y))
+ assert_((np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) > 0), "arctan(%s, %s) is %s, not +inf" % (x, y, ncu.arctan2(x, y)))
def assert_arctan2_isninf(x, y):
- assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) < 0), "arctan(%s, %s) is %s, not -inf" % (x, y, ncu.arctan2(x, y))
+ assert_((np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) < 0), "arctan(%s, %s) is %s, not -inf" % (x, y, ncu.arctan2(x, y)))
def assert_arctan2_ispzero(x, y):
- assert (ncu.arctan2(x, y) == 0 and not np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not +0" % (x, y, ncu.arctan2(x, y))
+ assert_((ncu.arctan2(x, y) == 0 and not np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not +0" % (x, y, ncu.arctan2(x, y)))
def assert_arctan2_isnzero(x, y):
- assert (ncu.arctan2(x, y) == 0 and np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not -0" % (x, y, ncu.arctan2(x, y))
+ assert_((ncu.arctan2(x, y) == 0 and np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not -0" % (x, y, ncu.arctan2(x, y)))
class TestArctan2SpecialValues(TestCase):
@@ -897,7 +897,7 @@ class TestComplexFunctions(object):
if cname == 'asinh' and broken_cmath_asinh:
continue
- assert abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname,p,a,b)
+ assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s"%(fname,p,a,b))
def check_loss_of_precision(self, dtype):
"""Check loss of precision in complex arc* functions"""
@@ -913,23 +913,23 @@ class TestComplexFunctions(object):
z = x.astype(dtype)
d = np.absolute(np.arcsinh(x)/np.arcsinh(z).real - 1)
- assert np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
- 'arcsinh')
+ assert_(np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
+ 'arcsinh'))
z = (1j*x).astype(dtype)
d = np.absolute(np.arcsinh(x)/np.arcsin(z).imag - 1)
- assert np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
- 'arcsin')
+ assert_(np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
+ 'arcsin'))
z = x.astype(dtype)
d = np.absolute(np.arctanh(x)/np.arctanh(z).real - 1)
- assert np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
- 'arctanh')
+ assert_(np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
+ 'arctanh'))
z = (1j*x).astype(dtype)
d = np.absolute(np.arctanh(x)/np.arctan(z).imag - 1)
- assert np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
- 'arctan')
+ assert_(np.all(d < rtol), (np.argmax(d), x[np.argmax(d)], d.max(),
+ 'arctan'))
# The switchover was chosen as 1e-3; hence there can be up to
# ~eps/1e-3 of relative cancellation error before it
@@ -951,19 +951,19 @@ class TestComplexFunctions(object):
z = np.array([1e-5*(1+1j)], dtype=dtype)
p = 9.999999999333333333e-6 + 1.000000000066666666e-5j
d = np.absolute(1-np.arctanh(z)/p)
- assert np.all(d < 1e-15)
+ assert_(np.all(d < 1e-15))
p = 1.0000000000333333333e-5 + 9.999999999666666667e-6j
d = np.absolute(1-np.arcsinh(z)/p)
- assert np.all(d < 1e-15)
+ assert_(np.all(d < 1e-15))
p = 9.999999999333333333e-6j + 1.000000000066666666e-5
d = np.absolute(1-np.arctan(z)/p)
- assert np.all(d < 1e-15)
+ assert_(np.all(d < 1e-15))
p = 1.0000000000333333333e-5j + 9.999999999666666667e-6
d = np.absolute(1-np.arcsin(z)/p)
- assert np.all(d < 1e-15)
+ assert_(np.all(d < 1e-15))
# Check continuity across switchover points
@@ -971,11 +971,11 @@ class TestComplexFunctions(object):
z0 = np.asarray(z0, dtype=dtype)
zp = z0 + abs(z0) * d * eps * 2
zm = z0 - abs(z0) * d * eps * 2
- assert np.all(zp != zm), (zp, zm)
+ assert_(np.all(zp != zm), (zp, zm))
# NB: the cancellation error at the switchover is at least eps
good = (abs(func(zp) - func(zm)) < 2*eps)
- assert np.all(good), (func, z0[~good])
+ assert_(np.all(good), (func, z0[~good]))
for func in (np.arcsinh,np.arcsinh,np.arcsin,np.arctanh,np.arctan):
pts = [rp+1j*ip for rp in (-1e-3,0,1e-3) for ip in(-1e-3,0,1e-3)
@@ -997,7 +997,7 @@ class TestAttributes(TestCase):
def test_attributes(self):
add = ncu.add
assert_equal(add.__name__, 'add')
- assert add.__doc__.startswith('add(x1, x2[, out])\n\n')
+ assert_(add.__doc__.startswith('add(x1, x2[, out])\n\n'))
self.assertTrue(add.ntypes >= 18) # don't fail if types added
self.assertTrue('ii->i' in add.types)
assert_equal(add.nin, 2)
@@ -1049,10 +1049,10 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
yp = f(x0 + dx*scale*np.absolute(x0)/np.absolute(dx))
ym = f(x0 - dx*scale*np.absolute(x0)/np.absolute(dx))
- assert np.all(np.absolute(y0.real - yp.real) < atol), (y0, yp)
- assert np.all(np.absolute(y0.imag - yp.imag) < atol), (y0, yp)
- assert np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym)
- assert np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym)
+ assert_(np.all(np.absolute(y0.real - yp.real) < atol), (y0, yp))
+ assert_(np.all(np.absolute(y0.imag - yp.imag) < atol), (y0, yp))
+ assert_(np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym))
+ assert_(np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym))
if sig_zero_ok:
# check that signed zeros also work as a displacement
@@ -1066,30 +1066,30 @@ def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False,
ym = f(x)
ym = ym[jr | ji]
y0 = y0[jr | ji]
- assert np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym)
- assert np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym)
+ assert_(np.all(np.absolute(y0.real - ym.real*re_sign) < atol), (y0, ym))
+ assert_(np.all(np.absolute(y0.imag - ym.imag*im_sign) < atol), (y0, ym))
def test_copysign():
- assert np.copysign(1, -1) == -1
+ assert_(np.copysign(1, -1) == -1)
old_err = np.seterr(divide="ignore")
try:
- assert 1 / np.copysign(0, -1) < 0
- assert 1 / np.copysign(0, 1) > 0
+ assert_(1 / np.copysign(0, -1) < 0)
+ assert_(1 / np.copysign(0, 1) > 0)
finally:
np.seterr(**old_err)
- assert np.signbit(np.copysign(np.nan, -1))
- assert not np.signbit(np.copysign(np.nan, 1))
+ assert_(np.signbit(np.copysign(np.nan, -1)))
+ assert_(not np.signbit(np.copysign(np.nan, 1)))
def _test_nextafter(t):
one = t(1)
two = t(2)
zero = t(0)
eps = np.finfo(t).eps
- assert np.nextafter(one, two) - one == eps
- assert np.nextafter(one, zero) - one < 0
- assert np.isnan(np.nextafter(np.nan, one))
- assert np.isnan(np.nextafter(one, np.nan))
- assert np.nextafter(one, one) == one
+ assert_(np.nextafter(one, two) - one == eps)
+ assert_(np.nextafter(one, zero) - one < 0)
+ assert_(np.isnan(np.nextafter(np.nan, one)))
+ assert_(np.isnan(np.nextafter(one, np.nan)))
+ assert_(np.nextafter(one, one) == one)
def test_nextafter():
return _test_nextafter(np.float64)
@@ -1108,11 +1108,11 @@ def _test_spacing(t):
nan = t(np.nan)
inf = t(np.inf)
try:
- assert np.spacing(one) == eps
- assert np.isnan(np.spacing(nan))
- assert np.isnan(np.spacing(inf))
- assert np.isnan(np.spacing(-inf))
- assert np.spacing(t(1e30)) != 0
+ assert_(np.spacing(one) == eps)
+ assert_(np.isnan(np.spacing(nan)))
+ assert_(np.isnan(np.spacing(inf)))
+ assert_(np.isnan(np.spacing(-inf)))
+ assert_(np.spacing(t(1e30)) != 0)
finally:
np.seterr(**err)
@@ -1164,11 +1164,11 @@ def test_nextafter_vs_spacing():
for _f in [1, 1e-5, 1000]:
f = t(_f)
f1 = t(_f + 1)
- assert np.nextafter(f, f1) - f == np.spacing(f)
+ assert_(np.nextafter(f, f1) - f == np.spacing(f))
def test_pos_nan():
"""Check np.nan is a positive nan."""
- assert np.signbit(np.nan) == 0
+ assert_(np.signbit(np.nan) == 0)
def test_reduceat():
"""Test bug in reduceat when structured arrays are not copied."""
diff --git a/numpy/distutils/tests/test_fcompiler_gnu.py b/numpy/distutils/tests/test_fcompiler_gnu.py
index 3d727cd94..6a36fb160 100644
--- a/numpy/distutils/tests/test_fcompiler_gnu.py
+++ b/numpy/distutils/tests/test_fcompiler_gnu.py
@@ -24,26 +24,26 @@ class TestG77Versions(TestCase):
fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu')
for vs, version in g77_version_strings:
v = fc.version_match(vs)
- assert v == version, (vs, v)
+ assert_(v == version, (vs, v))
def test_not_g77(self):
fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu')
for vs, _ in gfortran_version_strings:
v = fc.version_match(vs)
- assert v is None, (vs, v)
+ assert_(v is None, (vs, v))
class TestGortranVersions(TestCase):
def test_gfortran_version(self):
fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu95')
for vs, version in gfortran_version_strings:
v = fc.version_match(vs)
- assert v == version, (vs, v)
+ assert_(v == version, (vs, v))
def test_not_gfortran(self):
fc = numpy.distutils.fcompiler.new_fcompiler(compiler='gnu95')
for vs, _ in g77_version_strings:
v = fc.version_match(vs)
- assert v is None, (vs, v)
+ assert_(v is None, (vs, v))
if __name__ == '__main__':
diff --git a/numpy/distutils/tests/test_misc_util.py b/numpy/distutils/tests/test_misc_util.py
index 6a671a931..448800b68 100644
--- a/numpy/distutils/tests/test_misc_util.py
+++ b/numpy/distutils/tests/test_misc_util.py
@@ -49,9 +49,9 @@ class TestGpaths(TestCase):
def test_gpaths(self):
local_path = minrelpath(join(dirname(__file__),'..'))
ls = gpaths('command/*.py', local_path)
- assert join(local_path,'command','build_src.py') in ls,`ls`
+ assert_(join(local_path,'command','build_src.py') in ls,`ls`)
f = gpaths('system_info.py', local_path)
- assert join(local_path,'system_info.py')==f[0],`f`
+ assert_(join(local_path,'system_info.py')==f[0],`f`)
if __name__ == "__main__":
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()
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index e1aa4afb8..3bcdb5e12 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -136,13 +136,13 @@ class TestSolve(LinalgTestCase, TestCase):
def do(self, a, b):
x = linalg.solve(a, b)
assert_almost_equal(b, dot(a, x))
- assert imply(isinstance(b, matrix), isinstance(x, matrix))
+ assert_(imply(isinstance(b, matrix), isinstance(x, matrix)))
class TestInv(LinalgTestCase, TestCase):
def do(self, a, b):
a_inv = linalg.inv(a)
assert_almost_equal(dot(a, a_inv), identity(asarray(a).shape[0]))
- assert imply(isinstance(a, matrix), isinstance(a_inv, matrix))
+ assert_(imply(isinstance(a, matrix), isinstance(a_inv, matrix)))
class TestEigvals(LinalgTestCase, TestCase):
def do(self, a, b):
@@ -154,14 +154,14 @@ class TestEig(LinalgTestCase, TestCase):
def do(self, a, b):
evalues, evectors = linalg.eig(a)
assert_almost_equal(dot(a, evectors), multiply(evectors, evalues))
- assert imply(isinstance(a, matrix), isinstance(evectors, matrix))
+ assert_(imply(isinstance(a, matrix), isinstance(evectors, matrix)))
class TestSVD(LinalgTestCase, TestCase):
def do(self, a, b):
u, s, vt = linalg.svd(a, 0)
assert_almost_equal(a, dot(multiply(u, s), vt))
- assert imply(isinstance(a, matrix), isinstance(u, matrix))
- assert imply(isinstance(a, matrix), isinstance(vt, matrix))
+ assert_(imply(isinstance(a, matrix), isinstance(u, matrix)))
+ assert_(imply(isinstance(a, matrix), isinstance(vt, matrix)))
class TestCondSVD(LinalgTestCase, TestCase):
def do(self, a, b):
@@ -184,7 +184,7 @@ class TestPinv(LinalgTestCase, TestCase):
def do(self, a, b):
a_ginv = linalg.pinv(a)
assert_almost_equal(dot(a, a_ginv), identity(asarray(a).shape[0]))
- assert imply(isinstance(a, matrix), isinstance(a_ginv, matrix))
+ assert_(imply(isinstance(a, matrix), isinstance(a_ginv, matrix)))
class TestDet(LinalgTestCase, TestCase):
def do(self, a, b):
@@ -237,8 +237,8 @@ class TestLstsq(LinalgTestCase, LinalgNonsquareTestCase, TestCase):
expect_resids = type(x)([])
assert_almost_equal(residuals, expect_resids)
assert_(np.issubdtype(residuals.dtype, np.floating))
- assert imply(isinstance(b, matrix), isinstance(x, matrix))
- assert imply(isinstance(b, matrix), isinstance(residuals, matrix))
+ assert_(imply(isinstance(b, matrix), isinstance(x, matrix)))
+ assert_(imply(isinstance(b, matrix), isinstance(residuals, matrix)))
class TestMatrixPower(object):
R90 = array([[0,1],[-1,0]])
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 070701089..2a2a76c24 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -596,14 +596,14 @@ class TestMaskedArray(TestCase):
ndtype = [('a', int), ('b', int)]
a = np.array([(1, 2,)], dtype=ndtype)[0]
f = mvoid(a)
- assert(isinstance(f, mvoid))
+ assert_(isinstance(f, mvoid))
#
a = masked_array([(1, 2)], mask=[(1, 0)], dtype=ndtype)[0]
- assert(isinstance(a, mvoid))
+ assert_(isinstance(a, mvoid))
#
a = masked_array([(1, 2), (1, 2)], mask=[(1, 0), (0, 0)], dtype=ndtype)
f = mvoid(a._data[0], a._mask[0])
- assert(isinstance(f, mvoid))
+ assert_(isinstance(f, mvoid))
def test_mvoid_getitem(self):
"Test mvoid.__getitem__"
@@ -752,8 +752,8 @@ class TestMaskedArrayArithmetic(TestCase):
def test_masked_singleton_equality(self):
"Tests (in)equality on masked snigleton"
a = array([1, 2, 3], mask=[1, 1, 0])
- assert((a[0] == 0) is masked)
- assert((a[0] != 0) is masked)
+ assert_((a[0] == 0) is masked)
+ assert_((a[0] != 0) is masked)
assert_equal((a[-1] == 0), False)
assert_equal((a[-1] != 0), True)
@@ -1520,7 +1520,7 @@ class TestFillingValues(TestCase):
b['a'] = a['a']
b['a'].set_fill_value(a['a'].fill_value)
f = b._fill_value[()]
- assert(np.isnan(f[0]))
+ assert_(np.isnan(f[0]))
assert_equal(f[-1], default_fill_value(1.))
def test_fillvalue_as_arguments(self):
@@ -2489,12 +2489,12 @@ class TestMaskedArrayMethods(TestCase):
# w/o mask: each entry is a np.void whose elements are standard Python
for entry in a:
for item in entry.tolist():
- assert(not isinstance(item, np.generic))
+ assert_(not isinstance(item, np.generic))
# w/ mask: each entry is a ma.void whose elements should be standard Python
a.mask[0] = (0, 1)
for entry in a:
for item in entry.tolist():
- assert(not isinstance(item, np.generic))
+ assert_(not isinstance(item, np.generic))
def test_toflex(self):
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index ac33ec0e5..082d36f95 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -770,13 +770,13 @@ class TestArraySetOps(TestCase):
a = array([1, 2, 3])
b = array([6, 5, 4])
test = setxor1d(a, b)
- assert(isinstance(test, MaskedArray))
+ assert_(isinstance(test, MaskedArray))
assert_equal(test, [1, 2, 3, 4, 5, 6])
#
a = array([1, 8, 2, 3], mask=[0, 1, 0, 0])
b = array([6, 5, 4, 8], mask=[0, 0, 0, 1])
test = setxor1d(a, b)
- assert(isinstance(test, MaskedArray))
+ assert_(isinstance(test, MaskedArray))
assert_equal(test, [1, 2, 3, 4, 5, 6])
#
assert_array_equal([], setxor1d([], []))
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index f068d4e50..a6ee33b72 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -48,7 +48,7 @@ class TestMRecords(TestCase):
mbase = base.view(mrecarray)
assert_equal(mbase.recordmask, base.recordmask)
assert_equal_records(mbase._mask, base._mask)
- assert isinstance(mbase._data, recarray)
+ assert_(isinstance(mbase._data, recarray))
assert_equal_records(mbase._data, base._data.view(recarray))
for field in ('a','b','c'):
assert_equal(base[field], mbase[field])
@@ -64,7 +64,7 @@ class TestMRecords(TestCase):
assert_equal(base[field], mbase[field])
# as elements .......
mbase_first = mbase[0]
- assert isinstance(mbase_first, mrecarray)
+ assert_(isinstance(mbase_first, mrecarray))
assert_equal(mbase_first.dtype, mbase.dtype)
assert_equal(mbase_first.tolist(), (1,1.1,asbytes('one')))
# Used to be mask, now it's recordmask
@@ -72,17 +72,17 @@ class TestMRecords(TestCase):
assert_equal(mbase_first._mask.item(), (False, False, False))
assert_equal(mbase_first['a'], mbase['a'][0])
mbase_last = mbase[-1]
- assert isinstance(mbase_last, mrecarray)
+ assert_(isinstance(mbase_last, mrecarray))
assert_equal(mbase_last.dtype, mbase.dtype)
assert_equal(mbase_last.tolist(), (None,None,None))
# Used to be mask, now it's recordmask
assert_equal(mbase_last.recordmask, True)
assert_equal(mbase_last._mask.item(), (True, True, True))
assert_equal(mbase_last['a'], mbase['a'][-1])
- assert (mbase_last['a'] is masked)
+ assert_((mbase_last['a'] is masked))
# as slice ..........
mbase_sl = mbase[:2]
- assert isinstance(mbase_sl, mrecarray)
+ assert_(isinstance(mbase_sl, mrecarray))
assert_equal(mbase_sl.dtype, mbase.dtype)
# Used to be mask, now it's recordmask
assert_equal(mbase_sl.recordmask, [0,1])
diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py
index 326104d7e..0f58741fa 100644
--- a/numpy/ma/tests/test_old_ma.py
+++ b/numpy/ma/tests/test_old_ma.py
@@ -169,13 +169,13 @@ class TestMa(TestCase):
self.assertEqual(1, count(1))
self.assertTrue (eq(0, array(1, mask=[1])))
ott = ott.reshape((2, 2))
- assert isinstance(count(ott, 0), numpy.ndarray)
+ assert_(isinstance(count(ott, 0), numpy.ndarray))
if sys.version_info[0] >= 3:
- assert isinstance(count(ott), numpy.integer)
+ assert_(isinstance(count(ott), numpy.integer))
else:
- assert isinstance(count(ott), types.IntType)
+ assert_(isinstance(count(ott), types.IntType))
self.assertTrue (eq(3, count(ott)))
- assert getmask(count(ott, 0)) is nomask
+ assert_(getmask(count(ott, 0)) is nomask)
self.assertTrue (eq([1, 2], count(ott, 0)))
def test_testMinMax (self):
@@ -220,38 +220,38 @@ class TestMa(TestCase):
x4 = array(x1)
# test conversion to strings
junk, garbage = str(x2), repr(x2)
- assert eq(numpy.sort(x1), sort(x2, fill_value=0))
+ assert_(eq(numpy.sort(x1), sort(x2, fill_value=0)))
# tests of indexing
- assert type(x2[1]) is type(x1[1])
- assert x1[1] == x2[1]
- assert x2[0] is masked
- assert eq(x1[2], x2[2])
- assert eq(x1[2:5], x2[2:5])
- assert eq(x1[:], x2[:])
- assert eq(x1[1:], x3[1:])
+ assert_(type(x2[1]) is type(x1[1]))
+ assert_(x1[1] == x2[1])
+ assert_(x2[0] is masked)
+ assert_(eq(x1[2], x2[2]))
+ assert_(eq(x1[2:5], x2[2:5]))
+ assert_(eq(x1[:], x2[:]))
+ assert_(eq(x1[1:], x3[1:]))
x1[2] = 9
x2[2] = 9
- assert eq(x1, x2)
+ assert_(eq(x1, x2))
x1[1:3] = 99
x2[1:3] = 99
- assert eq(x1, x2)
+ assert_(eq(x1, x2))
x2[1] = masked
- assert eq(x1, x2)
+ assert_(eq(x1, x2))
x2[1:3] = masked
- assert eq(x1, x2)
+ assert_(eq(x1, x2))
x2[:] = x1
x2[1] = masked
- assert allequal(getmask(x2), array([0, 1, 0, 0]))
+ assert_(allequal(getmask(x2), array([0, 1, 0, 0])))
x3[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x3), array([0, 1, 1, 0]))
+ assert_(allequal(getmask(x3), array([0, 1, 1, 0])))
x4[:] = masked_array([1, 2, 3, 4], [0, 1, 1, 0])
- assert allequal(getmask(x4), array([0, 1, 1, 0]))
- assert allequal(x4, array([1, 2, 3, 4]))
+ assert_(allequal(getmask(x4), array([0, 1, 1, 0])))
+ assert_(allequal(x4, array([1, 2, 3, 4])))
x1 = numpy.arange(5) * 1.0
x2 = masked_values(x1, 3.0)
- assert eq(x1, x2)
- assert allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask)
- assert eq(3.0, x2.fill_value)
+ assert_(eq(x1, x2))
+ assert_(allequal(array([0, 0, 0, 1, 0], MaskType), x2.mask))
+ assert_(eq(3.0, x2.fill_value))
x1 = array([1, 'hello', 2, 3], object)
x2 = numpy.array([1, 'hello', 2, 3], object)
s1 = x1[1]
@@ -259,7 +259,7 @@ class TestMa(TestCase):
self.assertEqual(type(s2), str)
self.assertEqual(type(s1), str)
self.assertEqual(s1, s2)
- assert x1[1:1].shape == (0,)
+ assert_(x1[1:1].shape == (0,))
def test_testCopySize(self):
"Tests of some subtle points of copying and sizing."
@@ -325,87 +325,87 @@ class TestMa(TestCase):
m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
i = numpy.nonzero(m)[0]
put(ym, i, zm)
- assert all(take(ym, i, axis=0) == zm)
+ assert_(all(take(ym, i, axis=0) == zm))
def test_testOddFeatures(self):
"Test of other odd features"
x = arange(20); x = x.reshape(4, 5)
x.flat[5] = 12
- assert x[1, 0] == 12
+ assert_(x[1, 0] == 12)
z = x + 10j * x
- assert eq(z.real, x)
- assert eq(z.imag, 10 * x)
- assert eq((z * conjugate(z)).real, 101 * x * x)
+ assert_(eq(z.real, x))
+ assert_(eq(z.imag, 10 * x))
+ assert_(eq((z * conjugate(z)).real, 101 * x * x))
z.imag[...] = 0.0
x = arange(10)
x[3] = masked
- assert str(x[3]) == str(masked)
+ assert_(str(x[3]) == str(masked))
c = x >= 8
- assert count(where(c, masked, masked)) == 0
- assert shape(where(c, masked, masked)) == c.shape
+ assert_(count(where(c, masked, masked)) == 0)
+ assert_(shape(where(c, masked, masked)) == c.shape)
z = where(c , x, masked)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is masked
- assert z[7] is masked
- assert z[8] is not masked
- assert z[9] is not masked
- assert eq(x, z)
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is masked)
+ assert_(z[7] is masked)
+ assert_(z[8] is not masked)
+ assert_(z[9] is not masked)
+ assert_(eq(x, z))
z = where(c , masked, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
z = masked_where(c, x)
- assert z.dtype is x.dtype
- assert z[3] is masked
- assert z[4] is not masked
- assert z[7] is not masked
- assert z[8] is masked
- assert z[9] is masked
- assert eq(x, z)
+ assert_(z.dtype is x.dtype)
+ assert_(z[3] is masked)
+ assert_(z[4] is not masked)
+ assert_(z[7] is not masked)
+ assert_(z[8] is masked)
+ assert_(z[9] is masked)
+ assert_(eq(x, z))
x = array([1., 2., 3., 4., 5.])
c = array([1, 1, 1, 0, 0])
x[2] = masked
z = where(c, x, -x)
- assert eq(z, [1., 2., 0., -4., -5])
+ assert_(eq(z, [1., 2., 0., -4., -5]))
c[0] = masked
z = where(c, x, -x)
- assert eq(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
- assert eq(masked_where(greater(x, 2), x), masked_greater(x, 2))
- assert eq(masked_where(greater_equal(x, 2), x),
- masked_greater_equal(x, 2))
- assert eq(masked_where(less(x, 2), x), masked_less(x, 2))
- assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x, 2))
- assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2))
- assert eq(masked_where(equal(x, 2), x), masked_equal(x, 2))
- assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2))
- assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])
- assert eq(masked_outside(range(5), 1, 3), [199, 1, 2, 3, 199])
- assert eq(masked_inside(array(range(5), mask=[1, 0, 0, 0, 0]), 1, 3).mask,
- [1, 1, 1, 1, 0])
- assert eq(masked_outside(array(range(5), mask=[0, 1, 0, 0, 0]), 1, 3).mask,
- [1, 1, 0, 0, 1])
- assert eq(masked_equal(array(range(5), mask=[1, 0, 0, 0, 0]), 2).mask,
- [1, 0, 1, 0, 0])
- assert eq(masked_not_equal(array([2, 2, 1, 2, 1], mask=[1, 0, 0, 0, 0]), 2).mask,
- [1, 0, 1, 0, 1])
- assert eq(masked_where([1, 1, 0, 0, 0], [1, 2, 3, 4, 5]), [99, 99, 3, 4, 5])
+ assert_(eq(z, [1., 2., 0., -4., -5]))
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
+ assert_(eq(masked_where(greater(x, 2), x), masked_greater(x, 2)))
+ assert_(eq(masked_where(greater_equal(x, 2), x),
+ masked_greater_equal(x, 2)))
+ assert_(eq(masked_where(less(x, 2), x), masked_less(x, 2)))
+ assert_(eq(masked_where(less_equal(x, 2), x), masked_less_equal(x, 2)))
+ assert_(eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2)))
+ assert_(eq(masked_where(equal(x, 2), x), masked_equal(x, 2)))
+ assert_(eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2)))
+ assert_(eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4]))
+ assert_(eq(masked_outside(range(5), 1, 3), [199, 1, 2, 3, 199]))
+ assert_(eq(masked_inside(array(range(5), mask=[1, 0, 0, 0, 0]), 1, 3).mask,
+ [1, 1, 1, 1, 0]))
+ assert_(eq(masked_outside(array(range(5), mask=[0, 1, 0, 0, 0]), 1, 3).mask,
+ [1, 1, 0, 0, 1]))
+ assert_(eq(masked_equal(array(range(5), mask=[1, 0, 0, 0, 0]), 2).mask,
+ [1, 0, 1, 0, 0]))
+ assert_(eq(masked_not_equal(array([2, 2, 1, 2, 1], mask=[1, 0, 0, 0, 0]), 2).mask,
+ [1, 0, 1, 0, 1]))
+ assert_(eq(masked_where([1, 1, 0, 0, 0], [1, 2, 3, 4, 5]), [99, 99, 3, 4, 5]))
atest = ones((10, 10, 10), dtype=float32)
btest = zeros(atest.shape, MaskType)
ctest = masked_where(btest, atest)
- assert eq(atest, ctest)
+ assert_(eq(atest, ctest))
z = choose(c, (-x, x))
- assert eq(z, [1., 2., 0., -4., -5])
- assert z[0] is masked
- assert z[1] is not masked
- assert z[2] is masked
+ assert_(eq(z, [1., 2., 0., -4., -5]))
+ assert_(z[0] is masked)
+ assert_(z[1] is not masked)
+ assert_(z[2] is masked)
x = arange(6)
x[5] = masked
y = arange(6) * 10
@@ -414,26 +414,26 @@ class TestMa(TestCase):
cm = c.filled(1)
z = where(c, x, y)
zm = where(cm, x, y)
- assert eq(z, zm)
- assert getmask(zm) is nomask
- assert eq(zm, [0, 1, 2, 30, 40, 50])
+ assert_(eq(z, zm))
+ assert_(getmask(zm) is nomask)
+ assert_(eq(zm, [0, 1, 2, 30, 40, 50]))
z = where(c, masked, 1)
- assert eq(z, [99, 99, 99, 1, 1, 1])
+ assert_(eq(z, [99, 99, 99, 1, 1, 1]))
z = where(c, 1, masked)
- assert eq(z, [99, 1, 1, 99, 99, 99])
+ assert_(eq(z, [99, 1, 1, 99, 99, 99]))
def test_testMinMax(self):
"Test of minumum, maximum."
- assert eq(minimum([1, 2, 3], [4, 0, 9]), [1, 0, 3])
- assert eq(maximum([1, 2, 3], [4, 0, 9]), [4, 2, 9])
+ assert_(eq(minimum([1, 2, 3], [4, 0, 9]), [1, 0, 3]))
+ assert_(eq(maximum([1, 2, 3], [4, 0, 9]), [4, 2, 9]))
x = arange(5)
y = arange(5) - 2
x[3] = masked
y[0] = masked
- assert eq(minimum(x, y), where(less(x, y), x, y))
- assert eq(maximum(x, y), where(greater(x, y), x, y))
- assert minimum(x) == 0
- assert maximum(x) == 4
+ assert_(eq(minimum(x, y), where(less(x, y), x, y)))
+ assert_(eq(maximum(x, y), where(greater(x, y), x, y)))
+ assert_(minimum(x) == 0)
+ assert_(maximum(x) == 4)
def test_testTakeTransposeInnerOuter(self):
"Test of take, transpose, inner, outer products"
@@ -442,18 +442,18 @@ class TestMa(TestCase):
x[5:6] = masked
x = x.reshape(2, 3, 4)
y = y.reshape(2, 3, 4)
- assert eq(numpy.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1)))
- assert eq(numpy.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1))
- assert eq(numpy.inner(filled(x, 0), filled(y, 0)),
- inner(x, y))
- assert eq(numpy.outer(filled(x, 0), filled(y, 0)),
- outer(x, y))
+ assert_(eq(numpy.transpose(y, (2, 0, 1)), transpose(x, (2, 0, 1))))
+ assert_(eq(numpy.take(y, (2, 0, 1), 1), take(x, (2, 0, 1), 1)))
+ assert_(eq(numpy.inner(filled(x, 0), filled(y, 0)),
+ inner(x, y)))
+ assert_(eq(numpy.outer(filled(x, 0), filled(y, 0)),
+ outer(x, y)))
y = array(['abc', 1, 'def', 2, 3], object)
y[2] = masked
t = take(y, [0, 3, 4])
- assert t[0] == 'abc'
- assert t[1] == 2
- assert t[2] == 3
+ assert_(t[0] == 'abc')
+ assert_(t[1] == 2)
+ assert_(t[2] == 3)
def test_testInplace(self):
"""Test of inplace operations and rich comparisons"""
@@ -463,47 +463,47 @@ class TestMa(TestCase):
xm = arange(10)
xm[2] = masked
x += 1
- assert eq(x, y + 1)
+ assert_(eq(x, y + 1))
xm += 1
- assert eq(x, y + 1)
+ assert_(eq(x, y + 1))
x = arange(10)
xm = arange(10)
xm[2] = masked
x -= 1
- assert eq(x, y - 1)
+ assert_(eq(x, y - 1))
xm -= 1
- assert eq(xm, y - 1)
+ assert_(eq(xm, y - 1))
x = arange(10) * 1.0
xm = arange(10) * 1.0
xm[2] = masked
x *= 2.0
- assert eq(x, y * 2)
+ assert_(eq(x, y * 2))
xm *= 2.0
- assert eq(xm, y * 2)
+ assert_(eq(xm, y * 2))
x = arange(10) * 2
xm = arange(10)
xm[2] = masked
x /= 2
- assert eq(x, y)
+ assert_(eq(x, y))
xm /= 2
- assert eq(x, y)
+ assert_(eq(x, y))
x = arange(10) * 1.0
xm = arange(10) * 1.0
xm[2] = masked
x /= 2.0
- assert eq(x, y / 2.0)
+ assert_(eq(x, y / 2.0))
xm /= arange(10)
- assert eq(xm, ones((10,)))
+ assert_(eq(xm, ones((10,))))
x = arange(10).astype(float32)
xm = arange(10)
xm[2] = masked
x += 1.
- assert eq(x, y + 1.)
+ assert_(eq(x, y + 1.))
def test_testPickle(self):
"Test of pickling"
@@ -513,7 +513,7 @@ class TestMa(TestCase):
x = x.reshape(4, 3)
s = pickle.dumps(x)
y = pickle.loads(s)
- assert eq(x, y)
+ assert_(eq(x, y))
def test_testMasked(self):
"Test of masked element"
diff --git a/numpy/ma/testutils.py b/numpy/ma/testutils.py
index 5cfc9f2ab..4fb76b330 100644
--- a/numpy/ma/testutils.py
+++ b/numpy/ma/testutils.py
@@ -142,6 +142,7 @@ def fail_if_equal(actual, desired, err_msg='',):
msg = build_err_msg([actual, desired], err_msg)
if not desired != actual:
raise AssertionError(msg)
+
assert_not_equal = fail_if_equal
@@ -230,7 +231,7 @@ def assert_array_less(x, y, err_msg='', verbose=True):
def assert_mask_equal(m1, m2, err_msg=''):
"""Asserts the equality of two masks."""
if m1 is nomask:
- assert(m2 is nomask)
+ assert_(m2 is nomask)
if m2 is nomask:
- assert(m1 is nomask)
+ assert_(m1 is nomask)
assert_array_equal(m1, m2, err_msg=err_msg)
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py
index ccb68f0e7..09a4b4892 100644
--- a/numpy/matrixlib/tests/test_defmatrix.py
+++ b/numpy/matrixlib/tests/test_defmatrix.py
@@ -9,7 +9,7 @@ class TestCtor(TestCase):
def test_basic(self):
A = array([[1,2],[3,4]])
mA = matrix(A)
- assert all(mA.A == A)
+ assert_(all(mA.A == A))
B = bmat("A,A;A,A")
C = bmat([[A,A], [A,A]])
@@ -17,16 +17,16 @@ class TestCtor(TestCase):
[3,4,3,4],
[1,2,1,2],
[3,4,3,4]])
- assert all(B.A == D)
- assert all(C.A == D)
+ assert_(all(B.A == D))
+ assert_(all(C.A == D))
E = array([[5,6],[7,8]])
AEresult = matrix([[1,2,5,6],[3,4,7,8]])
- assert all(bmat([A,E]) == AEresult)
+ assert_(all(bmat([A,E]) == AEresult))
vec = arange(5)
mvec = matrix(vec)
- assert mvec.shape == (1,5)
+ assert_(mvec.shape == (1,5))
def test_bmat_nondefault_str(self):
A = array([[1,2],[3,4]])
@@ -43,12 +43,12 @@ class TestCtor(TestCase):
[3,4,7,8],
[5,6,1,2],
[7,8,3,4]])
- assert all(bmat("A,A;A,A") == Aresult)
- assert all(bmat("A,A;A,A",ldict={'A':B}) == Aresult)
+ assert_(all(bmat("A,A;A,A") == Aresult))
+ assert_(all(bmat("A,A;A,A",ldict={'A':B}) == Aresult))
assert_raises(TypeError, bmat, "A,A;A,A",gdict={'A':B})
- assert all(bmat("A,A;A,A",ldict={'A':A},gdict={'A':B}) == Aresult)
+ assert_(all(bmat("A,A;A,A",ldict={'A':A},gdict={'A':B}) == Aresult))
b2 = bmat("A,B;C,D",ldict={'A':A,'B':B},gdict={'C':B,'D':A})
- assert all(b2 == mixresult)
+ assert_(all(b2 == mixresult))
class TestProperties(TestCase):
@@ -65,35 +65,35 @@ class TestProperties(TestCase):
sumall = 30
assert_array_equal(sum0, M.sum(axis=0))
assert_array_equal(sum1, M.sum(axis=1))
- assert sumall == M.sum()
+ assert_(sumall == M.sum())
def test_prod(self):
x = matrix([[1,2,3],[4,5,6]])
- assert x.prod() == 720
- assert all(x.prod(0) == matrix([[4,10,18]]))
- assert all(x.prod(1) == matrix([[6],[120]]))
+ assert_(x.prod() == 720)
+ assert_(all(x.prod(0) == matrix([[4,10,18]])))
+ assert_(all(x.prod(1) == matrix([[6],[120]])))
y = matrix([0,1,3])
- assert y.prod() == 0
+ assert_(y.prod() == 0)
def test_max(self):
x = matrix([[1,2,3],[4,5,6]])
- assert x.max() == 6
- assert all(x.max(0) == matrix([[4,5,6]]))
- assert all(x.max(1) == matrix([[3],[6]]))
+ assert_(x.max() == 6)
+ assert_(all(x.max(0) == matrix([[4,5,6]])))
+ assert_(all(x.max(1) == matrix([[3],[6]])))
def test_min(self):
x = matrix([[1,2,3],[4,5,6]])
- assert x.min() == 1
- assert all(x.min(0) == matrix([[1,2,3]]))
- assert all(x.min(1) == matrix([[1],[4]]))
+ assert_(x.min() == 1)
+ assert_(all(x.min(0) == matrix([[1,2,3]])))
+ assert_(all(x.min(1) == matrix([[1],[4]])))
def test_ptp(self):
x = np.arange(4).reshape((2,2))
- assert x.ptp() == 3
- assert all(x.ptp(0) == array([2, 2]))
- assert all(x.ptp(1) == array([1, 1]))
+ assert_(x.ptp() == 3)
+ assert_(all(x.ptp(0) == array([2, 2])))
+ assert_(all(x.ptp(1) == array([1, 1])))
def test_var(self):
x = np.arange(9).reshape((3,3))
@@ -107,16 +107,16 @@ class TestProperties(TestCase):
A = array([[1., 2.],
[3., 4.]])
mA = matrix(A)
- assert allclose(linalg.inv(A), mA.I)
- assert all(array(transpose(A) == mA.T))
- assert all(array(transpose(A) == mA.H))
- assert all(A == mA.A)
+ assert_(allclose(linalg.inv(A), mA.I))
+ assert_(all(array(transpose(A) == mA.T)))
+ assert_(all(array(transpose(A) == mA.H)))
+ assert_(all(A == mA.A))
B = A + 2j*A
mB = matrix(B)
- assert allclose(linalg.inv(B), mB.I)
- assert all(array(transpose(B) == mB.T))
- assert all(array(conjugate(transpose(B)) == mB.H))
+ assert_(allclose(linalg.inv(B), mB.I))
+ assert_(all(array(transpose(B) == mB.T)))
+ assert_(all(array(conjugate(transpose(B)) == mB.H)))
def test_pinv(self):
x = matrix(arange(6).reshape(2,3))
@@ -129,40 +129,40 @@ class TestProperties(TestCase):
A = arange(100).reshape(10,10)
mA = matrix(A)
mB = matrix(A) + 0.1
- assert all(mB == A+0.1)
- assert all(mB == matrix(A+0.1))
- assert not any(mB == matrix(A-0.1))
- assert all(mA < mB)
- assert all(mA <= mB)
- assert all(mA <= mA)
- assert not any(mA < mA)
-
- assert not any(mB < mA)
- assert all(mB >= mA)
- assert all(mB >= mB)
- assert not any(mB > mB)
-
- assert all(mA == mA)
- assert not any(mA == mB)
- assert all(mB != mA)
-
- assert not all(abs(mA) > 0)
- assert all(abs(mB > 0))
+ assert_(all(mB == A+0.1))
+ assert_(all(mB == matrix(A+0.1)))
+ assert_(not any(mB == matrix(A-0.1)))
+ assert_(all(mA < mB))
+ assert_(all(mA <= mB))
+ assert_(all(mA <= mA))
+ assert_(not any(mA < mA))
+
+ assert_(not any(mB < mA))
+ assert_(all(mB >= mA))
+ assert_(all(mB >= mB))
+ assert_(not any(mB > mB))
+
+ assert_(all(mA == mA))
+ assert_(not any(mA == mB))
+ assert_(all(mB != mA))
+
+ assert_(not all(abs(mA) > 0))
+ assert_(all(abs(mB > 0)))
def test_asmatrix(self):
A = arange(100).reshape(10,10)
mA = asmatrix(A)
A[0,0] = -10
- assert A[0,0] == mA[0,0]
+ assert_(A[0,0] == mA[0,0])
def test_noaxis(self):
A = matrix([[1,0],[0,1]])
- assert A.sum() == matrix(2)
- assert A.mean() == matrix(0.5)
+ assert_(A.sum() == matrix(2))
+ assert_(A.mean() == matrix(0.5))
def test_repr(self):
A = matrix([[1,0],[0,1]])
- assert repr(A) == "matrix([[1, 0],\n [0, 1]])"
+ assert_(repr(A) == "matrix([[1, 0],\n [0, 1]])")
class TestCasting(TestCase):
def test_basic(self):
@@ -172,15 +172,15 @@ class TestCasting(TestCase):
mB = mA.copy()
O = ones((10,10), float64) * 0.1
mB = mB + O
- assert mB.dtype.type == float64
- assert all(mA != mB)
- assert all(mB == mA+0.1)
+ assert_(mB.dtype.type == float64)
+ assert_(all(mA != mB))
+ assert_(all(mB == mA+0.1))
mC = mA.copy()
O = ones((10,10), complex128)
mC = mC * O
- assert mC.dtype.type == complex128
- assert all(mA != mB)
+ assert_(mC.dtype.type == complex128)
+ assert_(all(mA != mB))
class TestAlgebra(TestCase):
@@ -193,22 +193,22 @@ class TestAlgebra(TestCase):
B = identity(2)
for i in xrange(6):
- assert allclose((mA ** i).A, B)
+ assert_(allclose((mA ** i).A, B))
B = dot(B, A)
Ainv = linalg.inv(A)
B = identity(2)
for i in xrange(6):
- assert allclose((mA ** -i).A, B)
+ assert_(allclose((mA ** -i).A, B))
B = dot(B, Ainv)
- assert allclose((mA * mA).A, dot(A, A))
- assert allclose((mA + mA).A, (A + A))
- assert allclose((3*mA).A, (3*A))
+ assert_(allclose((mA * mA).A, dot(A, A)))
+ assert_(allclose((mA + mA).A, (A + A)))
+ assert_(allclose((3*mA).A, (3*A)))
mA2 = matrix(A)
mA2 *= 3
- assert allclose(mA2.A, 3*A)
+ assert_(allclose(mA2.A, 3*A))
def test_pow(self):
"""Test raising a matrix to an integer power works as expected."""
@@ -278,12 +278,12 @@ class TestMatrixReturn(TestCase):
else:
args = ()
b = f(*args)
- assert type(b) is matrix, "%s" % attrib
- assert type(a.real) is matrix
- assert type(a.imag) is matrix
+ assert_(type(b) is matrix, "%s" % attrib)
+ assert_(type(a.real) is matrix)
+ assert_(type(a.imag) is matrix)
c,d = matrix([0.0]).nonzero()
- assert type(c) is matrix
- assert type(d) is matrix
+ assert_(type(c) is matrix)
+ assert_(type(d) is matrix)
class TestIndexing(TestCase):
@@ -316,13 +316,13 @@ class TestNewScalarIndexing(TestCase):
def test_fancy_indexing(self):
a = self.a
x = a[1, [0,1,0]]
- assert isinstance(x, matrix)
+ assert_(isinstance(x, matrix))
assert_equal(x, matrix([[3, 4, 3]]))
x = a[[1,0]]
- assert isinstance(x, matrix)
+ assert_(isinstance(x, matrix))
assert_equal(x, matrix([[3, 4], [1, 2]]))
x = a[[[1],[0]],[[1,0],[0,1]]]
- assert isinstance(x, matrix)
+ assert_(isinstance(x, matrix))
assert_equal(x, matrix([[4, 3], [1, 2]]))
def test_matrix_element(self):
@@ -365,9 +365,9 @@ class TestNewScalarIndexing(TestCase):
class TestPower(TestCase):
def test_returntype(self):
a = array([[0,1],[0,0]])
- assert type(matrix_power(a, 2)) is ndarray
+ assert_(type(matrix_power(a, 2)) is ndarray)
a = mat(a)
- assert type(matrix_power(a, 2)) is matrix
+ assert_(type(matrix_power(a, 2)) is matrix)
def test_list(self):
assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]])
diff --git a/numpy/matrixlib/tests/test_multiarray.py b/numpy/matrixlib/tests/test_multiarray.py
index 9f2dce7e4..9ef105aa3 100644
--- a/numpy/matrixlib/tests/test_multiarray.py
+++ b/numpy/matrixlib/tests/test_multiarray.py
@@ -4,7 +4,7 @@ from numpy.testing import *
class TestView(TestCase):
def test_type(self):
x = np.array([1,2,3])
- assert(isinstance(x.view(np.matrix),np.matrix))
+ assert_(isinstance(x.view(np.matrix),np.matrix))
def test_keywords(self):
x = np.array([(1,2)],dtype=[('a',np.int8),('b',np.int8)])
@@ -12,5 +12,5 @@ class TestView(TestCase):
y = x.view(dtype='<i2', type=np.matrix)
assert_array_equal(y,[[513]])
- assert(isinstance(y,np.matrix))
+ assert_(isinstance(y,np.matrix))
assert_equal(y.dtype, np.dtype('<i2'))
diff --git a/numpy/matrixlib/tests/test_regression.py b/numpy/matrixlib/tests/test_regression.py
index e85d34b23..ba0133dfd 100644
--- a/numpy/matrixlib/tests/test_regression.py
+++ b/numpy/matrixlib/tests/test_regression.py
@@ -12,11 +12,11 @@ class TestRegression(TestCase):
def test_matrix_properties(self,level=rlevel):
"""Ticket #125"""
a = np.matrix([1.0],dtype=float)
- assert(type(a.real) is np.matrix)
- assert(type(a.imag) is np.matrix)
+ assert_(type(a.real) is np.matrix)
+ assert_(type(a.imag) is np.matrix)
c,d = np.matrix([0.0]).nonzero()
- assert(type(c) is np.matrix)
- assert(type(d) is np.matrix)
+ assert_(type(c) is np.matrix)
+ assert_(type(d) is np.matrix)
def test_matrix_multiply_by_1d_vector(self, level=rlevel) :
"""Ticket #473"""
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
index 26118eda2..90e09f880 100644
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -74,7 +74,8 @@ def run_module_suite(file_to_run = None):
if file_to_run is None:
f = sys._getframe(1)
file_to_run = f.f_locals.get('__file__', None)
- assert file_to_run is not None
+ if file_to_run is None:
+ raise AssertionError
import_nose().run(argv=['',file_to_run])
@@ -149,7 +150,8 @@ class NoseTester(object):
if package is None:
f = sys._getframe(1)
package_path = f.f_locals.get('__file__', None)
- assert package_path is not None
+ if package_path is None:
+ raise AssertionError
package_path = os.path.dirname(package_path)
package_name = f.f_locals.get('__name__', None)
elif isinstance(package, type(os)):
@@ -202,7 +204,7 @@ class NoseTester(object):
print "nose version %d.%d.%d" % nose.__versioninfo__
- def prepare_test_args(self, label='fast', verbose=1, extra_argv=None,
+ def prepare_test_args(self, label='fast', verbose=1, extra_argv=None,
doctests=False, coverage=False):
"""
Run tests for module using nose.
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index a2d3119c5..423c75527 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -341,9 +341,8 @@ def print_assert_equal(test_string,actual,desired):
"""
import pprint
- try:
- assert(actual == desired)
- except AssertionError:
+
+ if not (actual == desired):
import cStringIO
msg = cStringIO.StringIO()
msg.write(test_string)
@@ -1117,7 +1116,7 @@ def _assert_valid_refcount(op):
for j in range(15):
d = op(b,c)
- assert(sys.getrefcount(i) >= rc)
+ assert_(sys.getrefcount(i) >= rc)
def assert_allclose(actual, desired, rtol=1e-7, atol=0,
err_msg='', verbose=True):