@@ -176,3 +176,50 @@ def test_match_event(
176
176
"""It should match a call to a rehearsal."""
177
177
result = match_event (event , rehearsal )
178
178
assert result is expected_result
179
+
180
+
181
+ def test_match_eq_override () -> None :
182
+ """It should prefer __eq__ from the rehearsal."""
183
+
184
+ class _Matcher :
185
+ def __eq__ (self , other : object ) -> bool :
186
+ return True
187
+
188
+ class _Value :
189
+ def __eq__ (self , other : object ) -> bool :
190
+ return False
191
+
192
+ event_args = SpyEvent (
193
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
194
+ payload = SpyCall (args = (_Value (),), kwargs = {}),
195
+ )
196
+
197
+ event_kwargs = SpyEvent (
198
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
199
+ payload = SpyCall (args = (), kwargs = {"value" : _Value ()}),
200
+ )
201
+
202
+ rehearsal_ars = WhenRehearsal (
203
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
204
+ payload = SpyCall (args = (_Matcher (),), kwargs = {}),
205
+ )
206
+
207
+ rehearsal_kwargs = WhenRehearsal (
208
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
209
+ payload = SpyCall (args = (), kwargs = {"value" : _Matcher ()}),
210
+ )
211
+
212
+ rehearsal_args_ignore_extra = WhenRehearsal (
213
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
214
+ payload = SpyCall (args = (_Matcher (),), kwargs = {}, ignore_extra_args = True ),
215
+ )
216
+
217
+ rehearsal_kwargs_ignore_extra = WhenRehearsal (
218
+ spy = SpyInfo (id = 42 , name = "my_spy" , is_async = False ),
219
+ payload = SpyCall (args = (), kwargs = {"value" : _Matcher ()}, ignore_extra_args = True ),
220
+ )
221
+
222
+ assert match_event (event_args , rehearsal_ars ) is True
223
+ assert match_event (event_kwargs , rehearsal_kwargs ) is True
224
+ assert match_event (event_args , rehearsal_args_ignore_extra ) is True
225
+ assert match_event (event_kwargs , rehearsal_kwargs_ignore_extra ) is True
0 commit comments