Check that numpy rel/abs args are handled correctly for comparison against an np.array Check both sides of the operator, hopefully it doesn't impact things. Test all permutations of where the approx and np.array() can show up
(self)
| 634 | assert actual != approx(list(expected), rel=5e-8, abs=0) |
| 635 | |
| 636 | def test_numpy_tolerance_args(self): |
| 637 | """ |
| 638 | Check that numpy rel/abs args are handled correctly |
| 639 | for comparison against an np.array |
| 640 | Check both sides of the operator, hopefully it doesn't impact things. |
| 641 | Test all permutations of where the approx and np.array() can show up |
| 642 | """ |
| 643 | np = pytest.importorskip("numpy") |
| 644 | expected = 100.0 |
| 645 | actual = 99.0 |
| 646 | abs_diff = expected - actual |
| 647 | rel_diff = (expected - actual) / expected |
| 648 | |
| 649 | tests = [ |
| 650 | (eq, abs_diff, 0), |
| 651 | (eq, 0, rel_diff), |
| 652 | (ne, 0, rel_diff / 2.0), # rel diff fail |
| 653 | (ne, abs_diff / 2.0, 0), # abs diff fail |
| 654 | ] |
| 655 | |
| 656 | for op, _abs, _rel in tests: |
| 657 | assert op(np.array(actual), approx(expected, abs=_abs, rel=_rel)) # a, b |
| 658 | assert op(approx(expected, abs=_abs, rel=_rel), np.array(actual)) # b, a |
| 659 | |
| 660 | assert op(actual, approx(np.array(expected), abs=_abs, rel=_rel)) # a, b |
| 661 | assert op(approx(np.array(expected), abs=_abs, rel=_rel), actual) # b, a |
| 662 | |
| 663 | assert op(np.array(actual), approx(np.array(expected), abs=_abs, rel=_rel)) |
| 664 | assert op(approx(np.array(expected), abs=_abs, rel=_rel), np.array(actual)) |
| 665 | |
| 666 | def test_numpy_expecting_nan(self): |
| 667 | np = pytest.importorskip("numpy") |