本文整理汇总了Python中unittest.mock.MagicMock.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.__file__方法的具体用法?Python MagicMock.__file__怎么用?Python MagicMock.__file__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.__file__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_do_reload
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [as 别名]
def test_do_reload(self, reload: MagicMock, os_path: MagicMock):
"""Should import the specified module and return True."""
target = MagicMock()
target.__file__ = 'fake'
os_path.getmtime.return_value = 10
self.assertTrue(reloading.do_reload(target, 0))
self.assertEqual(1, reload.call_count)
示例2: test_run_message_handler_for_bot
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [as 别名]
def test_run_message_handler_for_bot(self):
with patch('zulip_bots.lib.Client', new=FakeClient) as fake_client:
mock_lib_module = MagicMock()
# __file__ is not mocked by MagicMock(), so we assign a mock value manually.
mock_lib_module.__file__ = "foo"
mock_bot_handler = create_autospec(FakeBotHandler)
mock_lib_module.handler_class.return_value = mock_bot_handler
def call_on_each_event_mock(self, callback, event_types=None, narrow=None):
def test_message(message, flags):
event = {'message': message,
'flags': flags,
'type': 'message'}
callback(event)
# In the following test, expected_message is the dict that we expect
# to be passed to the bot's handle_message function.
original_message = {'content': '@**Alice** bar',
'type': 'stream'}
expected_message = {'type': 'stream',
'content': 'bar',
'full_content': '@**Alice** bar'}
test_message(original_message, {'mentioned'})
mock_bot_handler.handle_message.assert_called_with(
message=expected_message,
bot_handler=ANY)
fake_client.call_on_each_event = call_on_each_event_mock.__get__(
fake_client, fake_client.__class__)
run_message_handler_for_bot(lib_module=mock_lib_module,
quiet=True,
config_file=None,
bot_config_file=None,
bot_name='testbot')
示例3: test_do_reload_error
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [as 别名]
def test_do_reload_error(self, reload: MagicMock, os_path: MagicMock):
"""Should fail to import the specified module and so return False."""
target = MagicMock()
target.__file__ = None
target.__path__ = ['fake']
os_path.getmtime.return_value = 10
reload.side_effect = ImportError('FAKE')
self.assertFalse(reloading.do_reload(target, 0))
self.assertEqual(1, reload.call_count)
示例4: test_do_reload_skip
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [as 别名]
def test_do_reload_skip(self, reload: MagicMock, os_path: MagicMock):
"""
Should skip reloading the specified module because it hasn't been
modified and return False.
"""
target = MagicMock()
target.__file__ = 'fake'
os_path.getmtime.return_value = 0
self.assertFalse(reloading.do_reload(target, 10))
self.assertEqual(0, reload.call_count)
示例5: mock_openzwave
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [as 别名]
def mock_openzwave():
"""Mock out Open Z-Wave."""
libopenzwave = MagicMock()
libopenzwave.__file__ = 'test'
with patch.dict('sys.modules', {
'libopenzwave': libopenzwave,
'openzwave.option': MagicMock(),
'openzwave.network': MagicMock(),
'openzwave.group': MagicMock(),
}):
yield
示例6: test_init_no_name_with_main_mod
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import __file__ [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)