Skip to content

bpo-37555: Update _CallList.__contains__ to respect ANY #14700

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

Merged
merged 20 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
94ddf54
Flip equality to use mock calls' __eq__
ElizabethU Jul 11, 2019
b4c7d78
bpo-37555: Regression test demonstrating assert_has_calls not working…
ElizabethU Jul 14, 2019
ad99a9d
Revert "Flip equality to use mock calls' __eq__"
ElizabethU Jul 14, 2019
49c5310
bpo-37555: Add regression tests for mock ANY ordering issues
ElizabethU Jul 15, 2019
874fb69
bpo-37555: Fix _CallList and _Call order sensitivity
ElizabethU Jul 18, 2019
d72d6f5
bpo-37555: Ensure _call_matcher returns _Call object
ElizabethU Jul 20, 2019
f0e8411
Adding ACK and news entry
ElizabethU Jul 20, 2019
f295eac
bpo-37555: Replacing __eq__ with == to sidestep NotImplemented
ElizabethU Jul 20, 2019
18e964b
bpo-37555: cleaning up changes unnecessary to the final product
ElizabethU Jul 20, 2019
883841a
bpo-37555: Fixed call on bound arguments to respect args and kwargs
ElizabethU Jul 20, 2019
f4844c7
Revert "bpo-37555: Add regression tests for mock ANY ordering issues"
ElizabethU Jul 22, 2019
84489c8
Revert "bpo-37555: cleaning up changes unnecessary to the final product"
ElizabethU Jul 22, 2019
344ef17
Revert "bpo-37555: Replacing __eq__ with == to sidestep NotImplemented"
ElizabethU Jul 22, 2019
bdf430d
Revert "bpo-37555: Fix _CallList and _Call order sensitivity"
ElizabethU Jul 22, 2019
d3522b1
Updated NEWS.d
ElizabethU Jul 22, 2019
f47699d
bpo-37555: Add tests checking every function using _call_matcher both…
ElizabethU Aug 4, 2019
38650c9
bpo-37555: Ensure all assert methods using _call_matcher are actually…
ElizabethU Aug 5, 2019
24973c0
Remove AnyCompare and use call objects everywhere.
tirkarthi Aug 19, 2019
001d708
Revert "Remove AnyCompare and use call objects everywhere."
ElizabethU Sep 13, 2019
25dec66
Check for exception in assert_any_await
ElizabethU Sep 13, 2019
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
Prev Previous commit
Next Next commit
bpo-37555: Add tests checking every function using _call_matcher both…
… with and without spec
  • Loading branch information
ElizabethU committed Aug 5, 2019
commit f47699de12ca9aa7e79ade6ea958708f5b88eab8
28 changes: 26 additions & 2 deletions Lib/unittest/test/testmock/testasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import inspect
import unittest

from unittest.mock import (call, AsyncMock, patch, MagicMock, create_autospec,
_AwaitEvent)
from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock,
create_autospec, _AwaitEvent)


def tearDownModule():
Expand Down Expand Up @@ -599,6 +599,30 @@ def test_assert_has_awaits_no_order(self):
asyncio.run(self._runnable_test('SomethingElse'))
self.mock.assert_has_awaits(calls)

def test_awaits_asserts_with_any(self):
class Foo:
def __eq__(self, other): pass

asyncio.run(self._runnable_test(Foo(), 1))

self.mock.assert_has_awaits([call(ANY, 1)])
self.mock.assert_awaited_with(ANY, 1)
self.mock.assert_any_await(ANY, 1)

def test_awaits_asserts_with_spec_and_any(self):
class Foo:
def __eq__(self, other): pass

mock_with_spec = AsyncMock(spec=Foo)

async def _custom_mock_runnable_test(*args):
await mock_with_spec(*args)

asyncio.run(_custom_mock_runnable_test(Foo(), 1))
mock_with_spec.assert_has_awaits([call(ANY, 1)])
mock_with_spec.assert_awaited_with(ANY, 1)
mock_with_spec.assert_any_await(ANY, 1)

def test_assert_has_awaits_ordered(self):
calls = [call('NormalFoo'), call('baz')]
with self.assertRaises(AssertionError):
Expand Down
25 changes: 17 additions & 8 deletions Lib/unittest/test/testmock/testhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,29 @@ def __ne__(self, other): pass
]
self.assertEqual(expected, mock.mock_calls)
self.assertEqual(mock.mock_calls, expected)
mock.assert_has_calls(expected)

def test_assert_has_calls_with_any_and_spec_set(self):
def test_any_no_spec(self):
# This is a regression test for bpo-37555
class Foo(object):
class Foo:
def __eq__(self, other): pass
def __ne__(self, other): pass

mock = Mock(spec_set=Foo)
expected = [call(ANY)]
mock(Foo())
mock = Mock()
mock(Foo(), 1)
mock.assert_has_calls([call(ANY, 1)])
mock.assert_called_with(ANY, 1)
mock.assert_any_call(ANY, 1)

def test_any_and_spec_set(self):
# This is a regression test for bpo-37555
class Foo:
def __eq__(self, other): pass

mock.assert_has_calls(expected)
mock = Mock(spec=Foo)

mock(Foo(), 1)
mock.assert_has_calls([call(ANY, 1)])
mock.assert_called_with(ANY, 1)
mock.assert_any_call(ANY, 1)

class CallTest(unittest.TestCase):

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy