Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-61215: Rename wait_until_any_call to wait_until_any_call_with #106414

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ object::
>>> mock.wait_until_called(timeout=1)
>>> thread.join()

.. method:: wait_until_any_call(*args, **kwargs)
.. method:: wait_until_any_call_with(*args, **kwargs)

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

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

.. attribute:: DEFAULT_TIMEOUT
Expand Down
50 changes: 25 additions & 25 deletions Lib/test/test_unittest/testmock/testthreadingmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_no_name_clash(self):
waitable_mock.timeout = "mytimeout"
waitable_mock("works")
waitable_mock.wait_until_called()
waitable_mock.wait_until_any_call("works")
waitable_mock.wait_until_any_call_with("works")

def test_wait_success(self):
waitable_mock = self._make_mock(spec=Something)
Expand All @@ -96,7 +96,7 @@ def test_wait_success(self):
something = Something()
self.run_async(something.method_1, delay=0.01)
something.method_1.wait_until_called()
something.method_1.wait_until_any_call()
something.method_1.wait_until_any_call_with()
something.method_1.assert_called()

def test_wait_success_with_instance_timeout(self):
Expand All @@ -106,7 +106,7 @@ def test_wait_success_with_instance_timeout(self):
something = Something()
self.run_async(something.method_1, delay=0.01)
something.method_1.wait_until_called()
something.method_1.wait_until_any_call()
something.method_1.wait_until_any_call_with()
something.method_1.assert_called()

def test_wait_failed_with_instance_timeout(self):
Expand All @@ -117,7 +117,7 @@ def test_wait_failed_with_instance_timeout(self):
self.run_async(something.method_1, delay=0.5)
self.assertRaises(AssertionError, waitable_mock.method_1.wait_until_called)
self.assertRaises(
AssertionError, waitable_mock.method_1.wait_until_any_call
AssertionError, waitable_mock.method_1.wait_until_any_call_with
)

def test_wait_success_with_timeout_override(self):
Expand All @@ -137,7 +137,7 @@ def test_wait_failed_with_timeout_override(self):
with self.assertRaises(AssertionError):
something.method_1.wait_until_called(timeout=0.05)
with self.assertRaises(AssertionError):
something.method_1.wait_until_any_call(timeout=0.05)
something.method_1.wait_until_any_call_with(timeout=0.05)

def test_wait_success_called_before(self):
waitable_mock = self._make_mock()
Expand All @@ -146,7 +146,7 @@ def test_wait_success_called_before(self):
something = Something()
something.method_1()
something.method_1.wait_until_called()
something.method_1.wait_until_any_call()
something.method_1.wait_until_any_call_with()
something.method_1.assert_called()

def test_wait_magic_method(self):
Expand All @@ -158,7 +158,7 @@ def test_wait_magic_method(self):
something.method_1.__str__.wait_until_called()
something.method_1.__str__.assert_called()

def test_wait_until_any_call_positional(self):
def test_wait_until_any_call_with_positional(self):
waitable_mock = self._make_mock(spec=Something)

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

something.method_1.wait_until_any_call(1)
something.method_1.wait_until_any_call_with(1)
something.method_1.assert_called_with(1)
self.assertNotIn(call(2), something.method_1.mock_calls)
self.assertNotIn(call(3), something.method_1.mock_calls)

something.method_1.wait_until_any_call(3)
something.method_1.wait_until_any_call_with(3)
self.assertIn(call(2), something.method_1.mock_calls)
something.method_1.wait_until_any_call(2)
something.method_1.wait_until_any_call_with(2)

def test_wait_until_any_call_keywords(self):
def test_wait_until_any_call_with_keywords(self):
waitable_mock = self._make_mock(spec=Something)

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

something.method_1.wait_until_any_call(a=1)
something.method_1.wait_until_any_call_with(a=1)
something.method_1.assert_called_with(a=1)
self.assertNotIn(call(b=2), something.method_1.mock_calls)
self.assertNotIn(call(c=3), something.method_1.mock_calls)

something.method_1.wait_until_any_call(c=3)
something.method_1.wait_until_any_call_with(c=3)
self.assertIn(call(b=2), something.method_1.mock_calls)
something.method_1.wait_until_any_call(b=2)
something.method_1.wait_until_any_call_with(b=2)

def test_wait_until_any_call_no_argument_fails_when_called_with_arg(self):
def test_wait_until_any_call_with_no_argument_fails_when_called_with_arg(self):
waitable_mock = self._make_mock(timeout=0.01)

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

something.method_1.assert_called_with(1)
with self.assertRaises(AssertionError):
something.method_1.wait_until_any_call()
something.method_1.wait_until_any_call_with()

something.method_1()
something.method_1.wait_until_any_call()
something.method_1.wait_until_any_call_with()

def test_wait_until_any_call_global_default(self):
def test_wait_until_any_call_with_global_default(self):
with patch.object(ThreadingMock, "DEFAULT_TIMEOUT"):
ThreadingMock.DEFAULT_TIMEOUT = 0.01
m = self._make_mock()
with self.assertRaises(AssertionError):
m.wait_until_any_call()
m.wait_until_any_call_with()
with self.assertRaises(AssertionError):
m.wait_until_called()

m()
m.wait_until_any_call()
m.wait_until_any_call_with()
assert ThreadingMock.DEFAULT_TIMEOUT != 0.01

def test_wait_until_any_call_change_global_and_override(self):
def test_wait_until_any_call_with_change_global_and_override(self):
with patch.object(ThreadingMock, "DEFAULT_TIMEOUT"):
ThreadingMock.DEFAULT_TIMEOUT = 0.01

Expand Down Expand Up @@ -256,21 +256,21 @@ def test_reset_mock_resets_wait(self):
with self.assertRaises(AssertionError):
m.wait_until_called()
with self.assertRaises(AssertionError):
m.wait_until_any_call()
m.wait_until_any_call_with()
m()
m.wait_until_called()
m.wait_until_any_call()
m.wait_until_any_call_with()
m.assert_called_once()

m.reset_mock()

with self.assertRaises(AssertionError):
m.wait_until_called()
with self.assertRaises(AssertionError):
m.wait_until_any_call()
m.wait_until_any_call_with()
m()
m.wait_until_called()
m.wait_until_any_call()
m.wait_until_any_call_with()
m.assert_called_once()


Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@ def wait_until_called(self, *, timeout=_timeout_unset):
f" timeout({timeout}).")
raise AssertionError(msg)

def wait_until_any_call(self, *args, **kwargs):
def wait_until_any_call_with(self, *args, **kwargs):
"""Wait until the mock object is called with given args.

Waits for the timeout in seconds provided in the constructor.
Expand Down