Adds checks for nested data structures not of the same type as the outermost structure.
This commit is contained in:
parent
63d2f7f7f8
commit
70155264df
|
@ -376,7 +376,9 @@ class ApproxSequenceLike(ApproxBase):
|
||||||
def _check_type(self) -> None:
|
def _check_type(self) -> None:
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
for index, x in enumerate(self.expected):
|
for index, x in enumerate(self.expected):
|
||||||
if isinstance(x, type(self.expected)):
|
if (isinstance(x, Collection) or isinstance(x, Mapping)) and not isinstance(
|
||||||
|
x, STRING_TYPES
|
||||||
|
):
|
||||||
msg = "pytest.approx() does not support nested data structures: {!r} at index {}\n full sequence: {}"
|
msg = "pytest.approx() does not support nested data structures: {!r} at index {}\n full sequence: {}"
|
||||||
raise TypeError(msg.format(x, index, pprint.pformat(self.expected)))
|
raise TypeError(msg.format(x, index, pprint.pformat(self.expected)))
|
||||||
|
|
||||||
|
|
|
@ -781,6 +781,9 @@ class TestApprox:
|
||||||
"x, name",
|
"x, name",
|
||||||
[
|
[
|
||||||
pytest.param([[1]], "data structures", id="nested-list"),
|
pytest.param([[1]], "data structures", id="nested-list"),
|
||||||
|
pytest.param([(1,)], "data structures", id="nested-list-tuple"),
|
||||||
|
pytest.param([{1}], "data structures", id="nested-list-set"),
|
||||||
|
pytest.param([{"key": 1}], "data structures", id="nested-list-dict"),
|
||||||
pytest.param({"key": {"key": 1}}, "dictionaries", id="nested-dict"),
|
pytest.param({"key": {"key": 1}}, "dictionaries", id="nested-dict"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue