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


Python mock.patch方法代码示例

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


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

示例1: setUp

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def setUp(self):
        self.player = Player()

        self._get_audio_driver_patcher = mock.patch('pyglet.media.player.get_audio_driver')
        self.mock_get_audio_driver = self._get_audio_driver_patcher.start()
        self.mock_audio_driver = self.mock_get_audio_driver.return_value
        self.mock_audio_driver_player = self.mock_audio_driver.create_audio_player.return_value

        self._clock_patcher = mock.patch('pyglet.clock')
        self.mock_clock = self._clock_patcher.start()

        self._texture_patcher = mock.patch('pyglet.image.Texture.create')
        self.mock_texture_create = self._texture_patcher.start()
        self.mock_texture = self.mock_texture_create.return_value
        # Need to do this as side_effect instead of return_value, or reset_mock will recurse
        self.mock_texture.get_transform.side_effect = lambda flip_y: self.mock_texture 
开发者ID:pyglet,项目名称:pyglet,代码行数:18,代码来源:test_player.py

示例2: setUp

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def setUp(self):
        self.patch_host_config = mock.patch('freight_forwarder.container.host_config')
        self.patch_logger = mock.patch('freight_forwarder.container_ship.logger')
        self.patch_urlparse = mock.patch('freight_forwarder.container_ship.urlparse')
        self.patch_utils = mock.patch('freight_forwarder.container_ship.utils')
        self.patch_urllib = mock.patch('freight_forwarder.container_ship.urllib3')
        self.patch_docker_client = mock.patch('freight_forwarder.container_ship.docker.Client')
        self.patch_container = mock.patch('freight_forwarder.container_ship.Container')
        self.patch_image = mock.patch('freight_forwarder.container_ship.Image')

        self.mock_host_config = self.patch_host_config.start()
        self.mock_logger = self.patch_logger.start()
        self.mock_urlparse = self.patch_urlparse.start()
        self.mock_utils = self.patch_utils.start()
        self.mock_urllib = self.patch_urllib.start()
        self.mock_docker_client = self.patch_docker_client.start()
        self.mock_container = self.patch_container.start()
        self.mock_image = self.patch_image.start()

        self.mock_service = mock.Mock(spec=Service)

        self.injector = InjectorFactory() 
开发者ID:TUNE-Archive,项目名称:freight_forwarder,代码行数:24,代码来源:container_ship_test.py

示例3: _mock_console_input

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def _mock_console_input(self, isatty=True):
        with patch('streamlink_cli.console.sys.stdin.isatty', return_value=isatty):
            mock_console = MagicMock()
            mock_console.ask.return_value = "username"
            mock_console.askpass.return_value = "password"
            yield ConsoleUserInputRequester(mock_console) 
开发者ID:streamlink,项目名称:streamlink,代码行数:8,代码来源:test_plugins_input.py

示例4: test_load_fail

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_load_fail(self, exists_mock):
        if is_py2:
            patch('__builtin__.open', side_effect=IOError)
        else:
            patch('streamlink.cache.open', side_effect=IOError)
        self.cache._load()
        self.assertEqual({}, self.cache._cache) 
开发者ID:streamlink,项目名称:streamlink,代码行数:9,代码来源:test_cache.py

示例5: test_json_encoding

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_json_encoding(self):
        json_str = u"{\"test\": \"Α and Ω\"}"

        # encode the json string with each encoding and assert that the correct one is detected
        for encoding in ["UTF-32BE", "UTF-32LE", "UTF-16BE", "UTF-16LE", "UTF-8"]:
            with patch('requests.Response.content', new_callable=PropertyMock) as mock_content:
                mock_content.return_value = json_str.encode(encoding)
                res = requests.Response()

                self.assertEqual(HTTPSession.json(res), {u"test": u"\u0391 and \u03a9"}) 
开发者ID:streamlink,项目名称:streamlink,代码行数:12,代码来源:test_api_http_session.py

示例6: test_json_encoding_override

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_json_encoding_override(self):
        json_text = u"{\"test\": \"Α and Ω\"}".encode("cp949")

        with patch('requests.Response.content', new_callable=PropertyMock) as mock_content:
            mock_content.return_value = json_text
            res = requests.Response()
            res.encoding = "cp949"

            self.assertEqual(HTTPSession.json(res), {u"test": u"\u0391 and \u03a9"}) 
开发者ID:streamlink,项目名称:streamlink,代码行数:11,代码来源:test_api_http_session.py

示例7: setUp

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def setUp(self):
        self.session_patch = mock.patch('ibm_boto3.Session', autospec=True)
        self.Session = self.session_patch.start() 
开发者ID:IBM,项目名称:ibm-cos-sdk-python,代码行数:5,代码来源:test_boto3.py

示例8: _patch_directory

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def _patch_directory(self, target):
        directory = tempfile.mkdtemp()
        self._temporary_directories.append(directory)
        patcher = mock.patch(target, directory)
        self._patchers.append(patcher)
        patcher.start()
        return directory 
开发者ID:pyglet,项目名称:pyglet,代码行数:9,代码来源:test_interactive_test_base.py

示例9: test_player_silent_audio_driver

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_player_silent_audio_driver(player):
    with mock.patch('pyglet.media.player.get_audio_driver') as get_audio_driver_mock:
        get_audio_driver_mock.return_value = None
        source = SilentTestSource(.1)
        player.queue(source)
        player.play()

        player.wait_for_all_events(
            1.,
            'on_eos',
            'on_player_eos') 
开发者ID:pyglet,项目名称:pyglet,代码行数:13,代码来源:test_player.py

示例10: test_caching

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_caching(self):
        """
        Make sure cached values are held.
        Return values aren't accurate for blessed, but are sufficient for this test
        """

        handw = 'enlighten._terminal._Terminal._height_and_width'

        with mock.patch(handw, return_value=(1, 2)):
            self.assertEqual(self.terminal._height_and_width(), (1, 2))

        with mock.patch(handw, return_value=(5, 6)):
            self.assertEqual(self.terminal._height_and_width(), (1, 2))
            self.terminal.clear_cache()
            self.assertEqual(self.terminal._height_and_width(), (5, 6)) 
开发者ID:Rockhopper-Technologies,项目名称:enlighten,代码行数:17,代码来源:test_terminal.py

示例11: setUp

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def setUp(self):
        self.patch_requests = mock.patch('freight_forwarder.registry.registry_base.requests', autospec=True)
        self.patch_requests.start()
        self.test_registry = RegistryV1Factory(address="https://registrybasetest.docker.com") 
开发者ID:TUNE-Archive,项目名称:freight_forwarder,代码行数:6,代码来源:registry_test.py

示例12: setUp

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def setUp(self):
        # Patch sys.stdout for stream
        self.patch_utils_stdout = mock.patch("freight_forwarder.utils.utils.stdout", name="utils_sys")
        self.mock_utils_stdout = self.patch_utils_stdout.start()

        # Patch normalized_values
        self.patch_utils_normalize_keys = mock.patch("freight_forwarder.utils.utils.normalize_keys",
                                                     name="utils_normalize_keys")
        self.mock_utils_normalize_keys = self.patch_utils_normalize_keys.start()

        # Patch Display Error
        self.patch_display_error = mock.patch("freight_forwarder.utils.utils._display_error",
                                              name="mock_display_error")
        self.mock_display_error = self.patch_display_error.start()

        # Patch Display Progress
        self.patch_display_progress = mock.patch("freight_forwarder.utils.utils._display_progress",
                                                 name="mock_display_error")
        self.mock_display_progress = self.patch_display_progress.start()

        # Patch Display Status
        self.patch_display_status = mock.patch("freight_forwarder.utils.utils._display_status",
                                               name="mock_display_status")
        self.mock_display_status = self.patch_display_status.start()

        # Patch Display Stream
        self.patch_display_stream = mock.patch("freight_forwarder.utils.utils._display_stream",
                                               name="mock_display_stream")
        self.mock_display_stream = self.patch_display_stream.start()

        # Mock Response Object
        self.mock_object_request = mock.MagicMock(spec=requests.PreparedRequest, url="https://docker-host.test.io:2376")
        self.mock_object_response = mock.MagicMock(spec=requests.Response, request=self.mock_object_request)

        self.mock_object_response.status_code = 404 
开发者ID:TUNE-Archive,项目名称:freight_forwarder,代码行数:37,代码来源:utils_test.py

示例13: test_assemble_fleet_with_yaml_variables_in_hosts

# 需要导入模块: from tests import mock [as 别名]
# 或者: from tests.mock import patch [as 别名]
def test_assemble_fleet_with_yaml_variables_in_hosts(self,
                                                         mock_logger,
                                                         mock_container_ship,
                                                         mock_validate_commercial_invoice,
                                                         mock_write_state_file,
                                                         mock_service_deployment_validation,
                                                         mock_wait_for_dispatch,
                                                         mock_dispatch,
                                                         mock_complete_distribution
                                                         ):
        """
        Verify that feel is built correctly based on the provided configuration data
        :param mock_commercial_invoice:
        :return:
        """
        mock_registries = mock.patch.object(CommercialInvoice, '_create_registries', return_value={
            'tune_dev': RegistryV1Factory(),
            u'docker_hub': RegistryV1Factory()
        })
        mock_registries.start()
        mock_transport_service = mock.MagicMock(return_value='tomcat-test')

        self.freight_forwarder._bill_of_lading = {'failures': {}, 'successful': {}}
        commercial_invoice = self.freight_forwarder.commercial_invoice(
            action='deploy',
            data_center='local',
            environment='staging',
            transport_service=mock_transport_service()
        )
        mock_validate_commercial_invoice.return_value = commercial_invoice

        test_deployment = self.freight_forwarder.deploy_containers(
            commercial_invoice
        )

        # Ensure output of deployment is True based on no errors during the deployment process
        self.assertTrue(test_deployment)

        # Validate output of logging to ensure the correct host is output to the user
        calls = [call('Running deploy.'),
                 call('dispatching service: ffbug-example-tomcat-test on host: https://192.168.99.100:2376.')]
        mock_logger.info.assert_has_calls(calls) 
开发者ID:TUNE-Archive,项目名称:freight_forwarder,代码行数:44,代码来源:freight_forwarder_test.py


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