MCPcopy
hub / github.com/numpy/numpy / print_assert_equal

Function print_assert_equal

numpy/testing/_private/utils.py:471–509  ·  view source on GitHub ↗

Test if two objects are equal, and print an error message if test fails. The test is performed with ``actual == desired``. Parameters ---------- test_string : str The message supplied to AssertionError. actual : object The object to test for equality agains

(test_string, actual, desired)

Source from the content-addressed store, hash-verified

469
470
471def print_assert_equal(test_string, actual, desired):
472 """
473 Test if two objects are equal, and print an error message if test fails.
474
475 The test is performed with ``actual == desired``.
476
477 Parameters
478 ----------
479 test_string : str
480 The message supplied to AssertionError.
481 actual : object
482 The object to test for equality against `desired`.
483 desired : object
484 The expected result.
485
486 Examples
487 --------
488 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1])
489 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 2])
490 Traceback (most recent call last):
491 ...
492 AssertionError: Test XYZ of func xyz failed
493 ACTUAL:
494 [0, 1]
495 DESIRED:
496 [0, 2]
497
498 """
499 __tracebackhide__ = True # Hide traceback for py.test
500 import pprint
501
502 if not (actual == desired):
503 msg = StringIO()
504 msg.write(test_string)
505 msg.write(' failed\nACTUAL: \n')
506 pprint.pprint(actual, msg)
507 msg.write('DESIRED: \n')
508 pprint.pprint(desired, msg)
509 raise AssertionError(msg.getvalue())
510
511
512def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True):

Callers

nothing calls this directly

Calls 2

pprintMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…