本文整理匯總了Python中mock.mock._CallList方法的典型用法代碼示例。如果您正苦於以下問題:Python mock._CallList方法的具體用法?Python mock._CallList怎麽用?Python mock._CallList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mock.mock
的用法示例。
在下文中一共展示了mock._CallList方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_args_list_contains_call_list
# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import _CallList [as 別名]
def test_args_list_contains_call_list(self):
mock = Mock()
self.assertIsInstance(mock.call_args_list, _CallList)
mock(1, 2)
mock(a=3)
mock(3, 4)
mock(b=6)
for kall in call(1, 2), call(a=3), call(3, 4), call(b=6):
self.assertIn(kall, mock.call_args_list)
calls = [call(a=3), call(3, 4)]
self.assertIn(calls, mock.call_args_list)
calls = [call(1, 2), call(a=3)]
self.assertIn(calls, mock.call_args_list)
calls = [call(3, 4), call(b=6)]
self.assertIn(calls, mock.call_args_list)
calls = [call(3, 4)]
self.assertIn(calls, mock.call_args_list)
self.assertNotIn(call('fish'), mock.call_args_list)
self.assertNotIn([call('fish')], mock.call_args_list)
示例2: test_arg_lists
# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import _CallList [as 別名]
def test_arg_lists(self):
mocks = [
Mock(),
MagicMock(),
NonCallableMock(),
NonCallableMagicMock()
]
def assert_attrs(mock):
names = 'call_args_list', 'method_calls', 'mock_calls'
for name in names:
attr = getattr(mock, name)
self.assertIsInstance(attr, _CallList)
self.assertIsInstance(attr, list)
self.assertEqual(attr, [])
for mock in mocks:
assert_attrs(mock)
if callable(mock):
mock()
mock(1, 2)
mock(a=3)
mock.reset_mock()
assert_attrs(mock)
mock.foo()
mock.foo.bar(1, a=3)
mock.foo(1).bar().baz(3)
mock.reset_mock()
assert_attrs(mock)
示例3: test_async_arg_lists
# 需要導入模塊: from mock import mock [as 別名]
# 或者: from mock.mock import _CallList [as 別名]
def test_async_arg_lists(self):
def assert_attrs(mock):
names = ('call_args_list', 'method_calls', 'mock_calls')
for name in names:
attr = getattr(mock, name)
self.assertIsInstance(attr, _CallList)
self.assertIsInstance(attr, list)
self.assertEqual(attr, [])
assert_attrs(self.mock)
with assertNeverAwaited(self):
self.mock()
with assertNeverAwaited(self):
self.mock(1, 2)
with assertNeverAwaited(self):
self.mock(a=3)
self.mock.reset_mock()
assert_attrs(self.mock)
a_mock = AsyncMock(AsyncClass)
with assertNeverAwaited(self):
a_mock.async_method()
with assertNeverAwaited(self):
a_mock.async_method(1, a=3)
a_mock.reset_mock()
assert_attrs(a_mock)