Merge pull request #11178 from kenny-y-dev/add-none-support-approxmapping
This commit is contained in:
commit
d790e96765
|
@ -0,0 +1 @@
|
||||||
|
Fixed error assertion handling in :func:`pytest.approx` when ``None`` is an expected or received value when comparing dictionaries.
|
|
@ -265,6 +265,7 @@ class ApproxMapping(ApproxBase):
|
||||||
approx_side_as_map.items(), other_side.values()
|
approx_side_as_map.items(), other_side.values()
|
||||||
):
|
):
|
||||||
if approx_value != other_value:
|
if approx_value != other_value:
|
||||||
|
if approx_value.expected is not None and other_value is not None:
|
||||||
max_abs_diff = max(
|
max_abs_diff = max(
|
||||||
max_abs_diff, abs(approx_value.expected - other_value)
|
max_abs_diff, abs(approx_value.expected - other_value)
|
||||||
)
|
)
|
||||||
|
|
|
@ -122,6 +122,23 @@ class TestApprox:
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert_approx_raises_regex(
|
||||||
|
{"a": 1.0, "b": None, "c": None},
|
||||||
|
{
|
||||||
|
"a": None,
|
||||||
|
"b": 1000.0,
|
||||||
|
"c": None,
|
||||||
|
},
|
||||||
|
[
|
||||||
|
r" comparison failed. Mismatched elements: 2 / 3:",
|
||||||
|
r" Max absolute difference: -inf",
|
||||||
|
r" Max relative difference: -inf",
|
||||||
|
r" Index \| Obtained\s+\| Expected\s+",
|
||||||
|
rf" a \| {SOME_FLOAT} \| None",
|
||||||
|
rf" b \| None\s+\| {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
assert_approx_raises_regex(
|
assert_approx_raises_regex(
|
||||||
[1.0, 2.0, 3.0, 4.0],
|
[1.0, 2.0, 3.0, 4.0],
|
||||||
[1.0, 3.0, 3.0, 5.0],
|
[1.0, 3.0, 3.0, 5.0],
|
||||||
|
|
Loading…
Reference in New Issue