当前位置: 首页>>代码示例>>Python>>正文


Python MagicMock.__name__方法代码示例

本文整理汇总了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)
开发者ID:captainhammy,项目名称:Houdini-Toolbox,代码行数:28,代码来源:test_stats.py

示例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))
开发者ID:w3bcr4ft,项目名称:autonomie,代码行数:17,代码来源:test_taskaction.py

示例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))
开发者ID:mike-perdide,项目名称:autonomie,代码行数:17,代码来源:test_taskaction.py

示例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)
开发者ID:alanzxc,项目名称:py-junos-eznc,代码行数:9,代码来源:test_device.py

示例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)
开发者ID:alanzxc,项目名称:py-junos-eznc,代码行数:9,代码来源:test_device.py

示例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')
开发者ID:ganeshraju,项目名称:sparkmagic,代码行数:9,代码来源:test_exceptions.py

示例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
开发者ID:VinnieJohns,项目名称:ggrc-core,代码行数:10,代码来源:test_json.py

示例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)
开发者ID:dgjnpr,项目名称:py-junos-eznc,代码行数:10,代码来源:test_device.py

示例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)
开发者ID:adamchainz,项目名称:cache_requests,代码行数:11,代码来源:test_memoize.py

示例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"
开发者ID:Immortalem,项目名称:fluxscoreboard,代码行数:11,代码来源:test_challenge.py

示例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()
开发者ID:dls-controls,项目名称:malcolm,代码行数:11,代码来源:test_statemachine.py

示例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)
开发者ID:ganeshraju,项目名称:sparkmagic,代码行数:12,代码来源:test_exceptions.py

示例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')
开发者ID:ganeshraju,项目名称:sparkmagic,代码行数:12,代码来源:test_exceptions.py

示例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)
开发者ID:JesusAnaya,项目名称:mezzanine-rest-api,代码行数:12,代码来源:test_views.py

示例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')
开发者ID:ganeshraju,项目名称:sparkmagic,代码行数:12,代码来源:test_exceptions.py


注:本文中的mock.MagicMock.__name__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。