Skip to content

Commit 2dfc7fa

Browse files
authored
gh-61215: Rename wait_until_any_call to wait_until_any_call_with (#106414)
mock: Rename `wait_until_any_call` to `wait_until_any_call_with` Rename the method to be more explicit that it expects the args and kwargs to wait for.
1 parent 8a4bba8 commit 2dfc7fa

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

Doc/library/unittest.mock.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ object::
11261126
>>> mock.wait_until_called(timeout=1)
11271127
>>> thread.join()
11281128

1129-
.. method:: wait_until_any_call(*args, **kwargs)
1129+
.. method:: wait_until_any_call_with(*args, **kwargs)
11301130

11311131
Waits until the the mock is called with the specified arguments.
11321132

@@ -1136,7 +1136,7 @@ object::
11361136
>>> mock = ThreadingMock()
11371137
>>> thread = threading.Thread(target=mock, args=("arg1", "arg2",), kwargs={"arg": "thing"})
11381138
>>> thread.start()
1139-
>>> mock.wait_until_any_call("arg1", "arg2", arg="thing")
1139+
>>> mock.wait_until_any_call_with("arg1", "arg2", arg="thing")
11401140
>>> thread.join()
11411141

11421142
.. attribute:: DEFAULT_TIMEOUT

Lib/test/test_unittest/testmock/testthreadingmock.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_no_name_clash(self):
8787
waitable_mock.timeout = "mytimeout"
8888
waitable_mock("works")
8989
waitable_mock.wait_until_called()
90-
waitable_mock.wait_until_any_call("works")
90+
waitable_mock.wait_until_any_call_with("works")
9191

9292
def test_wait_success(self):
9393
waitable_mock = self._make_mock(spec=Something)
@@ -96,7 +96,7 @@ def test_wait_success(self):
9696
something = Something()
9797
self.run_async(something.method_1, delay=0.01)
9898
something.method_1.wait_until_called()
99-
something.method_1.wait_until_any_call()
99+
something.method_1.wait_until_any_call_with()
100100
something.method_1.assert_called()
101101

102102
def test_wait_success_with_instance_timeout(self):
@@ -106,7 +106,7 @@ def test_wait_success_with_instance_timeout(self):
106106
something = Something()
107107
self.run_async(something.method_1, delay=0.01)
108108
something.method_1.wait_until_called()
109-
something.method_1.wait_until_any_call()
109+
something.method_1.wait_until_any_call_with()
110110
something.method_1.assert_called()
111111

112112
def test_wait_failed_with_instance_timeout(self):
@@ -117,7 +117,7 @@ def test_wait_failed_with_instance_timeout(self):
117117
self.run_async(something.method_1, delay=0.5)
118118
self.assertRaises(AssertionError, waitable_mock.method_1.wait_until_called)
119119
self.assertRaises(
120-
AssertionError, waitable_mock.method_1.wait_until_any_call
120+
AssertionError, waitable_mock.method_1.wait_until_any_call_with
121121
)
122122

123123
def test_wait_success_with_timeout_override(self):
@@ -137,7 +137,7 @@ def test_wait_failed_with_timeout_override(self):
137137
with self.assertRaises(AssertionError):
138138
something.method_1.wait_until_called(timeout=0.05)
139139
with self.assertRaises(AssertionError):
140-
something.method_1.wait_until_any_call(timeout=0.05)
140+
something.method_1.wait_until_any_call_with(timeout=0.05)
141141

142142
def test_wait_success_called_before(self):
143143
waitable_mock = self._make_mock()
@@ -146,7 +146,7 @@ def test_wait_success_called_before(self):
146146
something = Something()
147147
something.method_1()
148148
something.method_1.wait_until_called()
149-
something.method_1.wait_until_any_call()
149+
something.method_1.wait_until_any_call_with()
150150
something.method_1.assert_called()
151151

152152
def test_wait_magic_method(self):
@@ -158,7 +158,7 @@ def test_wait_magic_method(self):
158158
something.method_1.__str__.wait_until_called()
159159
something.method_1.__str__.assert_called()
160160

161-
def test_wait_until_any_call_positional(self):
161+
def test_wait_until_any_call_with_positional(self):
162162
waitable_mock = self._make_mock(spec=Something)
163163

164164
with patch(f"{__name__}.Something", waitable_mock):
@@ -168,16 +168,16 @@ def test_wait_until_any_call_positional(self):
168168
self.run_async(something.method_1, 3, delay=0.3)
169169
self.assertNotIn(call(1), something.method_1.mock_calls)
170170

171-
something.method_1.wait_until_any_call(1)
171+
something.method_1.wait_until_any_call_with(1)
172172
something.method_1.assert_called_with(1)
173173
self.assertNotIn(call(2), something.method_1.mock_calls)
174174
self.assertNotIn(call(3), something.method_1.mock_calls)
175175

176-
something.method_1.wait_until_any_call(3)
176+
something.method_1.wait_until_any_call_with(3)
177177
self.assertIn(call(2), something.method_1.mock_calls)
178-
something.method_1.wait_until_any_call(2)
178+
something.method_1.wait_until_any_call_with(2)
179179

180-
def test_wait_until_any_call_keywords(self):
180+
def test_wait_until_any_call_with_keywords(self):
181181
waitable_mock = self._make_mock(spec=Something)
182182

183183
with patch(f"{__name__}.Something", waitable_mock):
@@ -187,16 +187,16 @@ def test_wait_until_any_call_keywords(self):
187187
self.run_async(something.method_1, c=3, delay=0.3)
188188
self.assertNotIn(call(a=1), something.method_1.mock_calls)
189189

190-
something.method_1.wait_until_any_call(a=1)
190+
something.method_1.wait_until_any_call_with(a=1)
191191
something.method_1.assert_called_with(a=1)
192192
self.assertNotIn(call(b=2), something.method_1.mock_calls)
193193
self.assertNotIn(call(c=3), something.method_1.mock_calls)
194194

195-
something.method_1.wait_until_any_call(c=3)
195+
something.method_1.wait_until_any_call_with(c=3)
196196
self.assertIn(call(b=2), something.method_1.mock_calls)
197-
something.method_1.wait_until_any_call(b=2)
197+
something.method_1.wait_until_any_call_with(b=2)
198198

199-
def test_wait_until_any_call_no_argument_fails_when_called_with_arg(self):
199+
def test_wait_until_any_call_with_no_argument_fails_when_called_with_arg(self):
200200
waitable_mock = self._make_mock(timeout=0.01)
201201

202202
with patch(f"{__name__}.Something", waitable_mock):
@@ -205,25 +205,25 @@ def test_wait_until_any_call_no_argument_fails_when_called_with_arg(self):
205205

206206
something.method_1.assert_called_with(1)
207207
with self.assertRaises(AssertionError):
208-
something.method_1.wait_until_any_call()
208+
something.method_1.wait_until_any_call_with()
209209

210210
something.method_1()
211-
something.method_1.wait_until_any_call()
211+
something.method_1.wait_until_any_call_with()
212212

213-
def test_wait_until_any_call_global_default(self):
213+
def test_wait_until_any_call_with_global_default(self):
214214
with patch.object(ThreadingMock, "DEFAULT_TIMEOUT"):
215215
ThreadingMock.DEFAULT_TIMEOUT = 0.01
216216
m = self._make_mock()
217217
with self.assertRaises(AssertionError):
218-
m.wait_until_any_call()
218+
m.wait_until_any_call_with()
219219
with self.assertRaises(AssertionError):
220220
m.wait_until_called()
221221

222222
m()
223-
m.wait_until_any_call()
223+
m.wait_until_any_call_with()
224224
assert ThreadingMock.DEFAULT_TIMEOUT != 0.01
225225

226-
def test_wait_until_any_call_change_global_and_override(self):
226+
def test_wait_until_any_call_with_change_global_and_override(self):
227227
with patch.object(ThreadingMock, "DEFAULT_TIMEOUT"):
228228
ThreadingMock.DEFAULT_TIMEOUT = 0.01
229229

@@ -256,21 +256,21 @@ def test_reset_mock_resets_wait(self):
256256
with self.assertRaises(AssertionError):
257257
m.wait_until_called()
258258
with self.assertRaises(AssertionError):
259-
m.wait_until_any_call()
259+
m.wait_until_any_call_with()
260260
m()
261261
m.wait_until_called()
262-
m.wait_until_any_call()
262+
m.wait_until_any_call_with()
263263
m.assert_called_once()
264264

265265
m.reset_mock()
266266

267267
with self.assertRaises(AssertionError):
268268
m.wait_until_called()
269269
with self.assertRaises(AssertionError):
270-
m.wait_until_any_call()
270+
m.wait_until_any_call_with()
271271
m()
272272
m.wait_until_called()
273-
m.wait_until_any_call()
273+
m.wait_until_any_call_with()
274274
m.assert_called_once()
275275

276276

Lib/unittest/mock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@ def wait_until_called(self, *, timeout=_timeout_unset):
30703070
f" timeout({timeout}).")
30713071
raise AssertionError(msg)
30723072

3073-
def wait_until_any_call(self, *args, **kwargs):
3073+
def wait_until_any_call_with(self, *args, **kwargs):
30743074
"""Wait until the mock object is called with given args.
30753075
30763076
Waits for the timeout in seconds provided in the constructor.

0 commit comments

Comments
 (0)