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


Python MagicMock.__file__方法代码示例

本文整理汇总了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)
开发者ID:sernst,项目名称:cauldron,代码行数:9,代码来源:test_session_reloading.py

示例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')
开发者ID:Juljan,项目名称:python-zulip-api,代码行数:36,代码来源:test_lib.py

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

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

示例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
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:13,代码来源:test_init.py

示例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)
开发者ID:knitori,项目名称:flowirc,代码行数:14,代码来源:test_IRCUser.py


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