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

Function build_err_msg

numpy/testing/_private/utils.py:184–209  ·  view source on GitHub ↗
(arrays, err_msg, header='Items are not equal:',
                  verbose=True, names=('ACTUAL', 'DESIRED'), precision=8)

Source from the content-addressed store, hash-verified

182
183
184def build_err_msg(arrays, err_msg, header='Items are not equal:',
185 verbose=True, names=('ACTUAL', 'DESIRED'), precision=8):
186 msg = ['\n' + header]
187 if err_msg:
188 if err_msg.find('\n') == -1 and len(err_msg) < 79-len(header):
189 msg = [msg[0] + ' ' + err_msg]
190 else:
191 msg.append(err_msg)
192 if verbose:
193 for i, a in enumerate(arrays):
194
195 if isinstance(a, ndarray):
196 # precision argument is only needed if the objects are ndarrays
197 r_func = partial(array_repr, precision=precision)
198 else:
199 r_func = repr
200
201 try:
202 r = r_func(a)
203 except Exception as exc:
204 r = f'[repr failed for <{type(a).__name__}>: {exc}]'
205 if r.count('\n') > 3:
206 r = '\n'.join(r.splitlines()[:3])
207 r += '...'
208 msg.append(f' {names[i]}: {r}')
209 return '\n'.join(msg)
210
211
212def assert_equal(actual, desired, err_msg='', verbose=True):

Callers 14

assert_array_compareMethod · 0.90
assert_equalFunction · 0.90
fail_if_equalFunction · 0.90
assert_almost_equalFunction · 0.90
assert_array_compareFunction · 0.90
assert_equalFunction · 0.85
_build_err_msgFunction · 0.85
assert_approx_equalFunction · 0.85

Calls 4

findMethod · 0.80
splitlinesMethod · 0.80
countMethod · 0.45
joinMethod · 0.45

Tested by 8

assert_equalFunction · 0.72
fail_if_equalFunction · 0.72
assert_almost_equalFunction · 0.72
assert_array_compareFunction · 0.72