[7.2.x] Add check for zero denominator in approx (#10689)

Co-authored-by: Jay <43951088+jayendra-patil33@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2023-01-24 10:30:54 +00:00
committed by GitHub
parent af22d34158
commit 76bef68f3e
3 changed files with 24 additions and 4 deletions

View File

@@ -630,6 +630,19 @@ class TestApprox:
def test_dict_vs_other(self):
assert 1 != approx({"a": 0})
def test_dict_for_div_by_zero(self, assert_approx_raises_regex):
assert_approx_raises_regex(
{"foo": 42.0},
{"foo": 0.0},
[
r" comparison failed. Mismatched elements: 1 / 1:",
rf" Max absolute difference: {SOME_FLOAT}",
r" Max relative difference: inf",
r" Index \| Obtained\s+\| Expected ",
rf" foo | {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}",
],
)
def test_numpy_array(self):
np = pytest.importorskip("numpy")