(left: Any, right: Any, verbose: int = 0)
| 176 | |
| 177 | |
| 178 | def _compare_eq_any(left: Any, right: Any, verbose: int = 0) -> List[str]: |
| 179 | explanation = [] |
| 180 | if istext(left) and istext(right): |
| 181 | explanation = _diff_text(left, right, verbose) |
| 182 | else: |
| 183 | from _pytest.python_api import ApproxBase |
| 184 | |
| 185 | if isinstance(left, ApproxBase) or isinstance(right, ApproxBase): |
| 186 | # Although the common order should be obtained == expected, this ensures both ways |
| 187 | approx_side = left if isinstance(left, ApproxBase) else right |
| 188 | other_side = right if isinstance(left, ApproxBase) else left |
| 189 | |
| 190 | explanation = approx_side._repr_compare(other_side) |
| 191 | elif type(left) == type(right) and ( |
| 192 | isdatacls(left) or isattrs(left) or isnamedtuple(left) |
| 193 | ): |
| 194 | # Note: unlike dataclasses/attrs, namedtuples compare only the |
| 195 | # field values, not the type or field names. But this branch |
| 196 | # intentionally only handles the same-type case, which was often |
| 197 | # used in older code bases before dataclasses/attrs were available. |
| 198 | explanation = _compare_eq_cls(left, right, verbose) |
| 199 | elif issequence(left) and issequence(right): |
| 200 | explanation = _compare_eq_sequence(left, right, verbose) |
| 201 | elif isset(left) and isset(right): |
| 202 | explanation = _compare_eq_set(left, right, verbose) |
| 203 | elif isdict(left) and isdict(right): |
| 204 | explanation = _compare_eq_dict(left, right, verbose) |
| 205 | elif verbose > 0: |
| 206 | explanation = _compare_eq_verbose(left, right) |
| 207 | |
| 208 | if isiterable(left) and isiterable(right): |
| 209 | expl = _compare_eq_iterable(left, right, verbose) |
| 210 | explanation.extend(expl) |
| 211 | |
| 212 | return explanation |
| 213 | |
| 214 | |
| 215 | def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]: |
no test coverage detected