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)
| 370 | |
| 371 | |
| 372 | def print_assert_equal(test_string, actual, desired): |
| 373 | """ |
| 374 | Test if two objects are equal, and print an error message if test fails. |
| 375 | |
| 376 | The test is performed with ``actual == desired``. |
| 377 | |
| 378 | Parameters |
| 379 | ---------- |
| 380 | test_string : str |
| 381 | The message supplied to AssertionError. |
| 382 | actual : object |
| 383 | The object to test for equality against `desired`. |
| 384 | desired : object |
| 385 | The expected result. |
| 386 | |
| 387 | Examples |
| 388 | -------- |
| 389 | >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 1]) |
| 390 | >>> np.testing.print_assert_equal('Test XYZ of func xyz', [0, 1], [0, 2]) |
| 391 | Traceback (most recent call last): |
| 392 | ... |
| 393 | AssertionError: Test XYZ of func xyz failed |
| 394 | ACTUAL: |
| 395 | [0, 1] |
| 396 | DESIRED: |
| 397 | [0, 2] |
| 398 | |
| 399 | """ |
| 400 | __tracebackhide__ = True # Hide traceback for py.test |
| 401 | import pprint |
| 402 | |
| 403 | if not (actual == desired): |
| 404 | msg = StringIO() |
| 405 | msg.write(test_string) |
| 406 | msg.write(' failed\nACTUAL: \n') |
| 407 | pprint.pprint(actual, msg) |
| 408 | msg.write('DESIRED: \n') |
| 409 | pprint.pprint(desired, msg) |
| 410 | raise AssertionError(msg.getvalue()) |
| 411 | |
| 412 | |
| 413 | @np._no_nep50_warning() |