MCPcopy Create free account
hub / github.com/pytorch/pytorch / print_assert_equal

Function print_assert_equal

torch/_numpy/testing/utils.py:285–323  ·  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

283
284
285def print_assert_equal(test_string, actual, desired):
286 """
287 Test if two objects are equal, and print an error message if test fails.
288
289 The test is performed with ``actual == desired``.
290
291 Parameters
292 ----------
293 test_string : str
294 The message supplied to AssertionError.
295 actual : object
296 The object to test for equality against `desired`.
297 desired : object
298 The expected result.
299
300 Examples
301 --------
302 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1]) # doctest: +SKIP
303 >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 2]) # doctest: +SKIP
304 Traceback (most recent call last):
305 ...
306 AssertionError: Test XYZ of func xyz failed
307 ACTUAL:
308 [0, 1]
309 DESIRED:
310 [0, 2]
311
312 """
313 __tracebackhide__ = True # Hide traceback for py.test
314 import pprint
315
316 if not (actual == desired):
317 msg = StringIO()
318 msg.write(test_string)
319 msg.write(" failed\nACTUAL: \n")
320 pprint.pprint(actual, msg)
321 msg.write("DESIRED: \n")
322 pprint.pprint(desired, msg)
323 raise AssertionError(msg.getvalue())
324
325
326def assert_almost_equal(actual, desired, decimal=7, err_msg="", verbose=True):

Callers

nothing calls this directly

Calls 3

pprintMethod · 0.80
writeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…