@@ -869,7 +869,7 @@ def assert_called_with(self, /, *args, **kwargs):
869
869
def _error_message ():
870
870
msg = self ._format_mock_failure_message (args , kwargs )
871
871
return msg
872
- expected = self ._call_matcher (_Call ((args , kwargs )))
872
+ expected = self ._call_matcher (_Call ((args , kwargs ), two = True ))
873
873
actual = self ._call_matcher (self .call_args )
874
874
if actual != expected :
875
875
cause = expected if isinstance (expected , Exception ) else None
@@ -932,9 +932,9 @@ def assert_any_call(self, /, *args, **kwargs):
932
932
`assert_called_with` and `assert_called_once_with` that only pass if
933
933
the call is the most recent one."""
934
934
expected = self ._call_matcher (_Call ((args , kwargs ), two = True ))
935
- cause = expected if isinstance (expected , Exception ) else None
936
935
actual = [self ._call_matcher (c ) for c in self .call_args_list ]
937
- if cause or expected not in _AnyComparer (actual ):
936
+ if expected not in actual :
937
+ cause = expected if isinstance (expected , Exception ) else None
938
938
expected_string = self ._format_mock_call_signature (args , kwargs )
939
939
raise AssertionError (
940
940
'%s call not found' % expected_string
@@ -987,23 +987,6 @@ def _calls_repr(self, prefix="Calls"):
987
987
return f"\n { prefix } : { safe_repr (self .mock_calls )} ."
988
988
989
989
990
- class _AnyComparer (list ):
991
- """A list which checks if it contains a call which may have an
992
- argument of ANY, flipping the components of item and self from
993
- their traditional locations so that ANY is guaranteed to be on
994
- the left."""
995
- def __contains__ (self , item ):
996
- for _call in self :
997
- if len (item ) != len (_call ):
998
- continue
999
- if all ([
1000
- expected == actual
1001
- for expected , actual in zip (item , _call )
1002
- ]):
1003
- return True
1004
- return False
1005
-
1006
-
1007
990
def _try_iter (obj ):
1008
991
if obj is None :
1009
992
return obj
@@ -2177,7 +2160,7 @@ def assert_any_await(self, /, *args, **kwargs):
2177
2160
"""
2178
2161
expected = self ._call_matcher (_Call ((args , kwargs ), two = True ))
2179
2162
actual = [self ._call_matcher (c ) for c in self .await_args_list ]
2180
- if expected not in _AnyComparer ( actual ) :
2163
+ if expected not in actual :
2181
2164
cause = expected if isinstance (expected , Exception ) else None
2182
2165
expected_string = self ._format_mock_call_signature (args , kwargs )
2183
2166
raise AssertionError (
0 commit comments