MCPcopy
hub / github.com/numpy/numpy / build_err_msg

Function build_err_msg

numpy/testing/_private/utils.py:231–257  ·  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

229
230
231def build_err_msg(arrays, err_msg, header='Items are not equal:',
232 verbose=True, names=('ACTUAL', 'DESIRED'), precision=8):
233 msg = ['\n' + header]
234 err_msg = str(err_msg)
235 if err_msg:
236 if err_msg.find('\n') == -1 and len(err_msg) < 79 - len(header):
237 msg = [msg[0] + ' ' + err_msg]
238 else:
239 msg.append(err_msg)
240 if verbose:
241 for i, a in enumerate(arrays):
242
243 if isinstance(a, ndarray):
244 # precision argument is only needed if the objects are ndarrays
245 r_func = partial(array_repr, precision=precision)
246 else:
247 r_func = repr
248
249 try:
250 r = r_func(a)
251 except Exception as exc:
252 r = f'[repr failed for <{type(a).__name__}>: {exc}]'
253 if r.count('\n') > 3:
254 r = '\n'.join(r.splitlines()[:3])
255 r += '...'
256 msg.append(f' {names[i]}: {r}')
257 return '\n'.join(msg)
258
259
260def assert_equal(actual, desired, err_msg='', verbose=True, *, strict=False):

Callers 14

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
func_assert_same_posFunction · 0.85

Calls 4

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

Tested by 8

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…