MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _compare_eq_any

Function _compare_eq_any

src/_pytest/assertion/util.py:178–212  ·  view source on GitHub ↗
(left: Any, right: Any, verbose: int = 0)

Source from the content-addressed store, hash-verified

176
177
178def _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
215def _diff_text(left: str, right: str, verbose: int = 0) -> List[str]:

Callers 2

assertrepr_compareFunction · 0.85
_compare_eq_clsFunction · 0.85

Calls 15

istextFunction · 0.85
_diff_textFunction · 0.85
isdataclsFunction · 0.85
isattrsFunction · 0.85
isnamedtupleFunction · 0.85
_compare_eq_clsFunction · 0.85
issequenceFunction · 0.85
_compare_eq_sequenceFunction · 0.85
issetFunction · 0.85
_compare_eq_setFunction · 0.85
isdictFunction · 0.85
_compare_eq_dictFunction · 0.85

Tested by

no test coverage detected