MCPcopy Create free account
hub / github.com/numpy/numpy / assert_equal

Function assert_equal

numpy/ma/testutils.py:108–144  ·  view source on GitHub ↗

Asserts that two items are equal.

(actual, desired, err_msg='')

Source from the content-addressed store, hash-verified

106
107
108def assert_equal(actual, desired, err_msg=''):
109 """
110 Asserts that two items are equal.
111
112 """
113 # Case #1: dictionary .....
114 if isinstance(desired, dict):
115 if not isinstance(actual, dict):
116 raise AssertionError(repr(type(actual)))
117 assert_equal(len(actual), len(desired), err_msg)
118 for k, i in desired.items():
119 if k not in actual:
120 raise AssertionError(f"{k} not in {actual}")
121 assert_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')
122 return
123 # Case #2: lists .....
124 if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):
125 return _assert_equal_on_sequences(actual, desired, err_msg='')
126 if not (isinstance(actual, ndarray) or isinstance(desired, ndarray)):
127 msg = build_err_msg([actual, desired], err_msg,)
128 if not desired == actual:
129 raise AssertionError(msg)
130 return
131 # Case #4. arrays or equivalent
132 if ((actual is masked) and not (desired is masked)) or \
133 ((desired is masked) and not (actual is masked)):
134 msg = build_err_msg([actual, desired],
135 err_msg, header='', names=('x', 'y'))
136 raise ValueError(msg)
137 actual = np.asanyarray(actual)
138 desired = np.asanyarray(desired)
139 (actual_dtype, desired_dtype) = (actual.dtype, desired.dtype)
140 if actual_dtype.char == "S" and desired_dtype.char == "S":
141 return _assert_equal_on_sequences(actual.tolist(),
142 desired.tolist(),
143 err_msg='')
144 return assert_array_equal(actual, desired, err_msg)
145
146
147def fail_if_equal(actual, desired, err_msg='',):

Callers 15

test_matrix_indexingMethod · 0.90
test_flatMethod · 0.90
test_compressedMethod · 0.90
test_ravelMethod · 0.90
test_viewMethod · 0.90
test_matrixMethod · 0.90

Calls 4

build_err_msgFunction · 0.90
assert_array_equalFunction · 0.70
tolistMethod · 0.45

Tested by

no test coverage detected