[7.1.x] Fix representation of tuples in approx
This commit is contained in:
@@ -2,12 +2,14 @@ import operator
|
||||
from contextlib import contextmanager
|
||||
from decimal import Decimal
|
||||
from fractions import Fraction
|
||||
from math import sqrt
|
||||
from operator import eq
|
||||
from operator import ne
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from _pytest.pytester import Pytester
|
||||
from _pytest.python_api import _recursive_sequence_map
|
||||
from pytest import approx
|
||||
|
||||
inf, nan = float("inf"), float("nan")
|
||||
@@ -133,6 +135,18 @@ class TestApprox:
|
||||
],
|
||||
)
|
||||
|
||||
assert_approx_raises_regex(
|
||||
(1, 2.2, 4),
|
||||
(1, 3.2, 4),
|
||||
[
|
||||
r" comparison failed. Mismatched elements: 1 / 3:",
|
||||
rf" Max absolute difference: {SOME_FLOAT}",
|
||||
rf" Max relative difference: {SOME_FLOAT}",
|
||||
r" Index \| Obtained\s+\| Expected ",
|
||||
rf" 1 \| {SOME_FLOAT} \| {SOME_FLOAT} ± {SOME_FLOAT}",
|
||||
],
|
||||
)
|
||||
|
||||
# Specific test for comparison with 0.0 (relative diff will be 'inf')
|
||||
assert_approx_raises_regex(
|
||||
[0.0],
|
||||
@@ -878,3 +892,31 @@ class TestApprox:
|
||||
"""pytest.approx() should raise an error on unordered sequences (#9692)."""
|
||||
with pytest.raises(TypeError, match="only supports ordered sequences"):
|
||||
assert {1, 2, 3} == approx({1, 2, 3})
|
||||
|
||||
|
||||
class TestRecursiveSequenceMap:
|
||||
def test_map_over_scalar(self):
|
||||
assert _recursive_sequence_map(sqrt, 16) == 4
|
||||
|
||||
def test_map_over_empty_list(self):
|
||||
assert _recursive_sequence_map(sqrt, []) == []
|
||||
|
||||
def test_map_over_list(self):
|
||||
assert _recursive_sequence_map(sqrt, [4, 16, 25, 676]) == [2, 4, 5, 26]
|
||||
|
||||
def test_map_over_tuple(self):
|
||||
assert _recursive_sequence_map(sqrt, (4, 16, 25, 676)) == (2, 4, 5, 26)
|
||||
|
||||
def test_map_over_nested_lists(self):
|
||||
assert _recursive_sequence_map(sqrt, [4, [25, 64], [[49]]]) == [
|
||||
2,
|
||||
[5, 8],
|
||||
[[7]],
|
||||
]
|
||||
|
||||
def test_map_over_mixed_sequence(self):
|
||||
assert _recursive_sequence_map(sqrt, [4, (25, 64), [(49)]]) == [
|
||||
2,
|
||||
(5, 8),
|
||||
[(7)],
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user