本文整理汇总了Python中mock.MagicMock.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.__name__方法的具体用法?Python MagicMock.__name__怎么用?Python MagicMock.__name__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.__name__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_time_function_existing
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_time_function_existing(self, mock_time, mock_item_stats):
mock_time.side_effect = (1, 2, 5, 8)
mock_func1 = MagicMock()
mock_func1.__name__ = MagicMock(spec=str)
mock_func2 = MagicMock()
mock_func2.__name__ = MagicMock(spec=str)
odict = OrderedDict()
odict[mock_func1.__name__] = 1
mock_item_stats.return_value = odict
stats = ht.events.stats.HoudiniEventItemStats(None)
with stats.time_function(mock_func1):
pass
with stats.time_function(mock_func2):
pass
expected = OrderedDict()
expected[mock_func1.__name__] = 2
expected[mock_func2.__name__] = 3
self.assertEqual(stats.item_stats, expected)
示例2: test_context_is_editable
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_context_is_editable(config, pyramid_request):
from autonomie.views.taskaction import context_is_editable
context = MagicMock()
context.__name__ = "invoice"
context.is_editable = lambda :True
assert(context_is_editable(None, context))
context = MagicMock()
context.__name__ = "notinvoice"
assert(context_is_editable(None, context))
context = MagicMock()
context.__name__ = 'invoice'
context.is_editable = lambda :False
context.is_waiting = lambda :True
pyramid_request.context = context
assert(context_is_editable(pyramid_request, context))
示例3: test_context_is_editable
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_context_is_editable(self):
context = MagicMock()
context.__name__ = "invoice"
context.is_editable = lambda :True
self.assertTrue(context_is_editable(None, context))
context = MagicMock()
context.__name__ = "notinvoice"
self.assertTrue(context_is_editable(None, context))
context = MagicMock()
context.__name__ = 'invoice'
context.is_editable = lambda :False
context.is_waiting = lambda :True
request = self.get_csrf_request()
request.context = context
self.assertTrue(context_is_editable(request, context))
示例4: varg
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def varg():
self.dev.bind()
mock = MagicMock()
mock.__name__ = 'magic mock'
#for *args
self.dev.bind(mock)
self.dev.bind(mock)
示例5: kve
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def kve():
self.dev.bind()
mock = MagicMock()
mock.__name__ = 'magic mock'
#for **kwargs
self.dev.bind(kw=mock)
self.dev.bind(kw=mock)
示例6: test_handle_expected_exceptions_throw
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_handle_expected_exceptions_throw():
mock_method = MagicMock(side_effect=ValueError('HALP'))
mock_method.__name__ = 'mock_meth'
decorated = handle_expected_exceptions(mock_method)
assert_equals(decorated.__name__, mock_method.__name__)
result = decorated(self, 1, kwarg='foo')
示例7: mock_class
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def mock_class(self, name, bases=(), _publish_attrs=None):
cls = MagicMock()
cls.__name__ = name
cls.__bases__ = bases
if _publish_attrs:
cls._publish_attrs = _publish_attrs
self.mock_builders.append(name)
return cls
示例8: test_device_bind_kvarg_exception
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_device_bind_kvarg_exception(self):
with self.assertRaises(ValueError):
self.dev.bind()
mock = MagicMock()
mock.__name__ = 'magic mock'
#for **kwargs
self.dev.bind(kw=mock)
self.dev.bind(kw=mock)
示例9: amazing_function
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def amazing_function():
from cache_requests import Memoize
def _side_effect(*args, **kwargs):
return len(args), len(kwargs)
_amazing_function = MagicMock(spec=_side_effect, side_effect=_side_effect)
_amazing_function.__name__ = 'amazing_function'
return Memoize(_amazing_function, ex=1)
示例10: module
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def module(self, request):
module = MagicMock()
module.__name__ = u"testmodule"
dynamic_challenges.registry[u"testmodule"] = module
def remove_module():
del dynamic_challenges.registry[u"testmodule"]
request.addfinalizer(remove_module)
return u"testmodule"
示例11: test_state1_2_transition_works
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_state1_2_transition_works(self):
trans = MagicMock(return_value=(VState.State2, "mess"))
trans.__name__ = "my_transition"
self.sm.transition(VState.State1, VEvent.Event1, trans, VState)
self.sm.loop_run()
self.sm.post(VEvent.Event1)
cothread.Yield()
self.assertEquals(self.sm.state, VState.State2)
trans.assert_called_once_with()
示例12: test_wrap_unexpected_exceptions
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_wrap_unexpected_exceptions():
mock_method = MagicMock()
mock_method.__name__ = 'tos'
decorated = wrap_unexpected_exceptions(mock_method)
assert_equals(decorated.__name__, mock_method.__name__)
result = decorated(self, 0.0)
assert_equals(result, mock_method.return_value)
assert_equals(ipython_display.send_error.call_count, 0)
mock_method.assert_called_once_with(self, 0.0)
示例13: test_handle_expected_exceptions_handle
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_handle_expected_exceptions_handle():
mock_method = MagicMock(side_effect=LivyUnexpectedStatusException('ridiculous'))
mock_method.__name__ = 'MockMethod2'
decorated = handle_expected_exceptions(mock_method)
assert_equals(decorated.__name__, mock_method.__name__)
result = decorated(self, 1, kwarg='foo')
assert_is(result, None)
assert_equals(ipython_display.send_error.call_count, 1)
mock_method.assert_called_once_with(self, 1, kwarg='foo')
示例14: test_create_a_mutable_viewset
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_create_a_mutable_viewset(self):
serializer_class = MagicMock(name='serializer_class')
model = MagicMock(name='model')
model.__name__ = 'BlogPost'
model.objects.all.return_value = []
viewset_class = MutableModelViewSet.create(model, serializer_class)
viewset = viewset_class()
self.assertEqual(viewset.queryset, [])
self.assertEqual(viewset.serializer_class, serializer_class)
示例15: test_wrap_unexpected_exceptions_handle
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import __name__ [as 别名]
def test_wrap_unexpected_exceptions_handle():
mock_method = MagicMock(side_effect=ValueError('~~~~~~'))
mock_method.__name__ = 'tos'
decorated = wrap_unexpected_exceptions(mock_method)
assert_equals(decorated.__name__, mock_method.__name__)
result = decorated(self, 'FOOBAR', FOOBAR='FOOBAR')
assert_is(result, None)
assert_equals(ipython_display.send_error.call_count, 1)
mock_method.assert_called_once_with(self, 'FOOBAR', FOOBAR='FOOBAR')