本文整理汇总了Python中mock.mock._Call方法的典型用法代码示例。如果您正苦于以下问题:Python mock._Call方法的具体用法?Python mock._Call怎么用?Python mock._Call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.mock
的用法示例。
在下文中一共展示了mock._Call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HasExactlyCalls
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def HasExactlyCalls(self, *calls):
"""Assert that the mocked function was called with exactly the given calls.
Args:
*calls: iterable of mock.call objects. Developers may also pass a single
iterable of mock.call objects, for compatibility with mock's
assert_has_calls() method, although this form is not preferred.
Returns:
If the mocked function was called exactly with the expected calls, returns
an _Ordered predicate on which .InOrder() can be subsequently called.
Raises:
TruthAssertionError: the mocked function is missing any of the expected
calls, or it contains any call not in the expected calls.
"""
# If the caller passed an iterable of mock.call objects, expand them.
# mock.call objects are themselves iterable, hence the third condition.
if (len(calls) == 1 and _IsIterable(calls[0])
# pylint: disable=protected-access
and not isinstance(calls[0], mock._Call)):
# pylint: enable=protected-access
calls = calls[0]
return AssertThat(self._actual.mock_calls).ContainsExactlyElementsIn(calls)
示例2: test_call_with_call
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_with_call(self):
kall = _Call()
self.assertEqual(kall, _Call())
self.assertEqual(kall, _Call(('',)))
self.assertEqual(kall, _Call(((),)))
self.assertEqual(kall, _Call(({},)))
self.assertEqual(kall, _Call(('', ())))
self.assertEqual(kall, _Call(('', {})))
self.assertEqual(kall, _Call(('', (), {})))
self.assertEqual(kall, _Call(('foo',)))
self.assertEqual(kall, _Call(('bar', ())))
self.assertEqual(kall, _Call(('baz', {})))
self.assertEqual(kall, _Call(('spam', (), {})))
kall = _Call(((1, 2, 3),))
self.assertEqual(kall, _Call(((1, 2, 3),)))
self.assertEqual(kall, _Call(('', (1, 2, 3))))
self.assertEqual(kall, _Call(((1, 2, 3), {})))
self.assertEqual(kall, _Call(('', (1, 2, 3), {})))
kall = _Call(((1, 2, 4),))
self.assertNotEqual(kall, _Call(('', (1, 2, 3))))
self.assertNotEqual(kall, _Call(('', (1, 2, 3), {})))
kall = _Call(('foo', (1, 2, 4),))
self.assertNotEqual(kall, _Call(('', (1, 2, 4))))
self.assertNotEqual(kall, _Call(('', (1, 2, 4), {})))
self.assertNotEqual(kall, _Call(('bar', (1, 2, 4))))
self.assertNotEqual(kall, _Call(('bar', (1, 2, 4), {})))
kall = _Call(({'a': 3},))
self.assertEqual(kall, _Call(('', (), {'a': 3})))
self.assertEqual(kall, _Call(('', {'a': 3})))
self.assertEqual(kall, _Call(((), {'a': 3})))
self.assertEqual(kall, _Call(({'a': 3},)))
示例3: test_empty__Call
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_empty__Call(self):
args = _Call()
self.assertEqual(args, ())
self.assertEqual(args, ('foo',))
self.assertEqual(args, ((),))
self.assertEqual(args, ('foo', ()))
self.assertEqual(args, ('foo',(), {}))
self.assertEqual(args, ('foo', {}))
self.assertEqual(args, ({},))
示例4: test_named_empty_call
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_named_empty_call(self):
args = _Call(('foo', (), {}))
self.assertEqual(args, ('foo',))
self.assertEqual(args, ('foo', ()))
self.assertEqual(args, ('foo',(), {}))
self.assertEqual(args, ('foo', {}))
self.assertNotEqual(args, ((),))
self.assertNotEqual(args, ())
self.assertNotEqual(args, ({},))
self.assertNotEqual(args, ('bar',))
self.assertNotEqual(args, ('bar', ()))
self.assertNotEqual(args, ('bar', {}))
示例5: test_call_with_args
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_with_args(self):
args = _Call(((1, 2, 3), {}))
self.assertEqual(args, ((1, 2, 3),))
self.assertEqual(args, ('foo', (1, 2, 3)))
self.assertEqual(args, ('foo', (1, 2, 3), {}))
self.assertEqual(args, ((1, 2, 3), {}))
示例6: test_named_call_with_args
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_named_call_with_args(self):
args = _Call(('foo', (1, 2, 3), {}))
self.assertEqual(args, ('foo', (1, 2, 3)))
self.assertEqual(args, ('foo', (1, 2, 3), {}))
self.assertNotEqual(args, ((1, 2, 3),))
self.assertNotEqual(args, ((1, 2, 3), {}))
示例7: test_named_call_with_kwargs
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_named_call_with_kwargs(self):
args = _Call(('foo', (), dict(a=3, b=4)))
self.assertEqual(args, ('foo', dict(a=3, b=4)))
self.assertEqual(args, ('foo', (), dict(a=3, b=4)))
self.assertNotEqual(args, (dict(a=3, b=4),))
self.assertNotEqual(args, ((), dict(a=3, b=4)))
示例8: test_call_with_args_call_empty_name
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_with_args_call_empty_name(self):
args = _Call(((1, 2, 3), {}))
self.assertEqual(args, call(1, 2, 3))
self.assertEqual(call(1, 2, 3), args)
self.assertIn(call(1, 2, 3), [args])
示例9: test_call_ne
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_ne(self):
self.assertNotEqual(_Call(((1, 2, 3),)), call(1, 2))
self.assertFalse(_Call(((1, 2, 3),)) != call(1, 2, 3))
self.assertTrue(_Call(((1, 2), {})) != call(1, 2, 3))
示例10: test_call_non_tuples
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_non_tuples(self):
kall = _Call(((1, 2, 3),))
for value in 1, None, self, int:
self.assertNotEqual(kall, value)
self.assertFalse(kall == value)
示例11: test_repr
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_repr(self):
self.assertEqual(repr(_Call()), 'call()')
self.assertEqual(repr(_Call(('foo',))), 'call.foo()')
self.assertEqual(repr(_Call(((1, 2, 3), {'a': 'b'}))),
"call(1, 2, 3, a='b')")
self.assertEqual(repr(_Call(('bar', (1, 2, 3), {'a': 'b'}))),
"call.bar(1, 2, 3, a='b')")
self.assertEqual(repr(call), 'call')
self.assertEqual(str(call), 'call')
self.assertEqual(repr(call()), 'call()')
self.assertEqual(repr(call(1)), 'call(1)')
self.assertEqual(repr(call(zz='thing')), "call(zz='thing')")
self.assertEqual(repr(call().foo), 'call().foo')
self.assertEqual(repr(call(1).foo.bar(a=3).bing),
'call().foo.bar().bing')
self.assertEqual(
repr(call().foo(1, 2, a=3)),
"call().foo(1, 2, a=3)"
)
self.assertEqual(repr(call()()), "call()()")
self.assertEqual(repr(call(1)(2)), "call()(2)")
self.assertEqual(
repr(call()().bar().baz.beep(1)),
"call()().bar().baz.beep(1)"
)
示例12: test_name_attribute_of_call
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_name_attribute_of_call(self):
# bpo-35357: _Call should not disclose any attributes whose names
# may clash with popular ones (such as ".name")
self.assertIsNotNone(call.name)
self.assertEqual(type(call.name), _Call)
self.assertEqual(type(call.name().name), _Call)
示例13: test_parent_attribute_of_call
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_parent_attribute_of_call(self):
# bpo-35357: _Call should not disclose any attributes whose names
# may clash with popular ones (such as ".parent")
self.assertIsNotNone(call.parent)
self.assertEqual(type(call.parent), _Call)
self.assertEqual(type(call.parent().parent), _Call)
示例14: test_named_call_with_args
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_named_call_with_args(self):
args = _Call(('foo', (1, 2, 3), {}))
self.assertEqual(args, ('foo', (1, 2, 3)))
self.assertEqual(args, ('foo', (1, 2, 3), {}))
self.assertEqual(args.args, (1, 2, 3))
self.assertEqual(args.kwargs, {})
self.assertNotEqual(args, ((1, 2, 3),))
self.assertNotEqual(args, ((1, 2, 3), {}))
示例15: test_call_with_kwargs
# 需要导入模块: from mock import mock [as 别名]
# 或者: from mock.mock import _Call [as 别名]
def test_call_with_kwargs(self):
args = _Call(((), dict(a=3, b=4)))
self.assertEqual(args, (dict(a=3, b=4),))
self.assertEqual(args, ('foo', dict(a=3, b=4)))
self.assertEqual(args, ('foo', (), dict(a=3, b=4)))
self.assertEqual(args, ((), dict(a=3, b=4)))
self.assertEqual(args.args, ())
self.assertEqual(args.kwargs, dict(a=3, b=4))