本文整理汇总了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)
示例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)
示例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")
示例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)
示例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)
示例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)