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


Python MagicMock.__name__方法代码示例

本文整理汇总了Python中unittest.mock.MagicMock.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.__name__方法的具体用法?Python MagicMock.__name__怎么用?Python MagicMock.__name__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.__name__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_render_with_typename

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_render_with_typename(self, select_template):
        model = MagicMock()
        model.__name__ = MagicMock()
        model.__name__.lower = MagicMock(return_value='model')
        model._meta.app_label = 'app_label'
        activity = MagicMock()
        activity.status = 'status'
        context = MagicMock()
        rendered = MagicMock()
        template = MagicMock()
        template.render.return_value = rendered
        select_template.return_value = template
        typename = 'test'

        mediator = ActivityMediator()
        mediator.connect(model)
        mediator.prepare_context = MagicMock(return_value=context.new())

        r = mediator.render(activity, context, typename=typename)

        select_template.assert_called_with(
            mediator.get_template_names(activity, typename=typename))
        mediator.prepare_context.assert_called_with(activity,
                                                    context.new(),
                                                    typename=typename)
        template.render.assert_called_with(context.new())
        self.assertEqual(r, rendered)
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:29,代码来源:test_mediator.py

示例2: test_load_trained_model_for_subquota

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_load_trained_model_for_subquota(self):
        ClassifierClass, classifier_instance = MagicMock(), MagicMock()
        ClassifierClass.return_value = classifier_instance
        ClassifierClass.__name__ = 'MonthlySubquotaLimitClassifier'

        settings = MagicMock()
        settings.UNIQUE_IDS = ['number']
        core = Core(settings, self.adapter)
        core.load_trained_model(ClassifierClass)

        classifier_instance.fit.assert_called_once_with(core.dataset)
开发者ID:datasciencebr,项目名称:serenata-de-amor,代码行数:13,代码来源:test_core_init.py

示例3: test_get_default_lists

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_get_default_lists(self, bl_mock):
        klass = MagicMock()
        klass.__name__ = "test"
        type(klass).last_saved = PropertyMock(return_value=datetime.now())
        klass.get_ips.return_value = ['1.1.1.1']

        bl_mock.get_class.return_value = klass

        url = "/{}".format(klass.__name__.lower())
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.mimetype, "text/plain")
开发者ID:SupportingIT,项目名称:blocklister,代码行数:14,代码来源:test_main.py

示例4: test_init_no_name_with_main_mod

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_init_no_name_with_main_mod(self):
        inspect_mod = Mock()
        inspect_mod.stack.return_value = MagicMock()
        mocked_module = MagicMock()
        mocked_module.__name__ = '__main__'
        mocked_module.__file__ = 'foo/bar.py'
        inspect_mod.getmodule.return_value = mocked_module
        bot = None
        with patch.dict('sys.modules', inspect=inspect_mod):
            bot = IRCUser()

        self.assertEqual('bar a Flowirc bot', bot.full_name)
开发者ID:knitori,项目名称:flowirc,代码行数:14,代码来源:test_IRCUser.py

示例5: test_load_trained_model_with_pickle

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_load_trained_model_with_pickle(self, joblib, isfile):
        isfile.return_value = True

        ClassifierClass, classifier_instance = MagicMock(), MagicMock()
        ClassifierClass.return_value = classifier_instance
        ClassifierClass.__name__ = 'ClassifierMock'

        settings = MagicMock()
        settings.UNIQUE_IDS = ['number']
        core = Core(settings, self.adapter)
        core.load_trained_model(ClassifierClass)

        expected_path = os.path.join('tmp', 'test', 'classifiermock.pkl')
        self.assertFalse(classifier_instance.fit.called)
        joblib.load.assert_called_once_with(expected_path)
开发者ID:datasciencebr,项目名称:serenata-de-amor,代码行数:17,代码来源:test_core_init.py

示例6: test_get_template_names

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __name__ [as 别名]
    def test_get_template_names(self):
        model = MagicMock()
        model.__name__ = MagicMock()
        model.__name__.lower = MagicMock(return_value='model')
        model._meta.app_label = 'app_label'
        activity = MagicMock()
        activity.status = 'status'

        mediator = ActivityMediator()
        mediator.get_template_extension = MagicMock(return_value='.html')
        mediator.connect(model)
        self.assertEqual(mediator.get_template_names(activity), (
                         'activities/app_label/model_status.html',
                         'activities/app_label/status.html',
                         'activities/status.html'))
        mediator.get_template_extension.assert_called_with(None)
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:18,代码来源:test_mediator.py


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