MCPcopy
hub / github.com/numpy/numpy / assert_equal

Function assert_equal

numpy/ma/testutils.py:114–150  ·  view source on GitHub ↗

Asserts that two items are equal.

(actual, desired, err_msg='')

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…