MCPcopy
hub / github.com/numpy/numpy / fail_if_equal

Function fail_if_equal

numpy/ma/testutils.py:153–176  ·  view source on GitHub ↗

Raises an assertion error if two items are equal.

(actual, desired, err_msg='',)

Source from the content-addressed store, hash-verified

151
152
153def fail_if_equal(actual, desired, err_msg='',):
154 """
155 Raises an assertion error if two items are equal.
156
157 """
158 if isinstance(desired, dict):
159 if not isinstance(actual, dict):
160 raise AssertionError(repr(type(actual)))
161 fail_if_equal(len(actual), len(desired), err_msg)
162 for k in desired:
163 if k not in actual:
164 raise AssertionError(repr(k))
165 fail_if_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')
166 return
167 if isinstance(desired, (list, tuple)) and isinstance(actual, (list, tuple)):
168 fail_if_equal(len(actual), len(desired), err_msg)
169 for k in range(len(desired)):
170 fail_if_equal(actual[k], desired[k], f'item={k!r}\n{err_msg}')
171 return
172 if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):
173 return fail_if_array_equal(actual, desired, err_msg)
174 msg = build_err_msg([actual, desired], err_msg)
175 if not desired != actual:
176 raise AssertionError(msg)
177
178
179assert_not_equal = fail_if_equal

Callers 2

test_basic1dMethod · 0.90

Calls 2

build_err_msgFunction · 0.90
fail_if_array_equalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…