@@ -148,26 +148,7 @@ def assertrepr_compare(config, op: str, left: Any, right: Any) -> Optional[List[
148
148
explanation = None
149
149
try :
150
150
if op == "==" :
151
- if istext (left ) and istext (right ):
152
- explanation = _diff_text (left , right , verbose )
153
- else :
154
- if issequence (left ) and issequence (right ):
155
- explanation = _compare_eq_sequence (left , right , verbose )
156
- elif isset (left ) and isset (right ):
157
- explanation = _compare_eq_set (left , right , verbose )
158
- elif isdict (left ) and isdict (right ):
159
- explanation = _compare_eq_dict (left , right , verbose )
160
- elif type (left ) == type (right ) and (isdatacls (left ) or isattrs (left )):
161
- type_fn = (isdatacls , isattrs )
162
- explanation = _compare_eq_cls (left , right , verbose , type_fn )
163
- elif verbose > 0 :
164
- explanation = _compare_eq_verbose (left , right )
165
- if isiterable (left ) and isiterable (right ):
166
- expl = _compare_eq_iterable (left , right , verbose )
167
- if explanation is not None :
168
- explanation .extend (expl )
169
- else :
170
- explanation = expl
151
+ explanation = _compare_eq_any (left , right , verbose )
171
152
elif op == "not in" :
172
153
if istext (left ) and istext (right ):
173
154
explanation = _notin_text (left , right , verbose )
@@ -187,6 +168,28 @@ def assertrepr_compare(config, op: str, left: Any, right: Any) -> Optional[List[
187
168
return [summary ] + explanation
188
169
189
170
171
+ def _compare_eq_any (left : Any , right : Any , verbose : int = 0 ) -> List [str ]:
172
+ explanation = [] # type: List[str]
173
+ if istext (left ) and istext (right ):
174
+ explanation = _diff_text (left , right , verbose )
175
+ else :
176
+ if issequence (left ) and issequence (right ):
177
+ explanation = _compare_eq_sequence (left , right , verbose )
178
+ elif isset (left ) and isset (right ):
179
+ explanation = _compare_eq_set (left , right , verbose )
180
+ elif isdict (left ) and isdict (right ):
181
+ explanation = _compare_eq_dict (left , right , verbose )
182
+ elif type (left ) == type (right ) and (isdatacls (left ) or isattrs (left )):
183
+ type_fn = (isdatacls , isattrs )
184
+ explanation = _compare_eq_cls (left , right , verbose , type_fn )
185
+ elif verbose > 0 :
186
+ explanation = _compare_eq_verbose (left , right )
187
+ if isiterable (left ) and isiterable (right ):
188
+ expl = _compare_eq_iterable (left , right , verbose )
189
+ explanation .extend (expl )
190
+ return explanation
191
+
192
+
190
193
def _diff_text (left : str , right : str , verbose : int = 0 ) -> List [str ]:
191
194
"""Return the explanation for the diff between text.
192
195
@@ -439,7 +442,8 @@ def _compare_eq_cls(
439
442
explanation += ["Differing attributes:" ]
440
443
for field in diff :
441
444
explanation += [
442
- ("%s: %r != %r" ) % (field , getattr (left , field ), getattr (right , field ))
445
+ ("%s: %r != %r" ) % (field , getattr (left , field ), getattr (right , field )),
446
+ * _compare_eq_any (getattr (left , field ), getattr (right , field ), verbose ),
443
447
]
444
448
return explanation
445
449
0 commit comments