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


Python patch.multiple方法代码示例

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


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

示例1: test_check_version_old

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_check_version_old(self):
        with patch.multiple(
            'awslimitchecker.checker',
            logger=DEFAULT,
            _get_version_info=DEFAULT,
            TrustedAdvisor=DEFAULT,
            _get_latest_version=DEFAULT,
            autospec=True,
        ) as mocks:
            mocks['_get_version_info'].return_value = self.mock_ver_info
            mocks['_get_latest_version'].return_value = '3.4.5'
            AwsLimitChecker()
        assert mocks['_get_latest_version'].mock_calls == [call()]
        assert mocks['logger'].mock_calls == [
            call.warning(
                'You are running awslimitchecker %s, but the latest version'
                ' is %s; please consider upgrading.', '1.2.3', '3.4.5'
            ),
            call.debug('Connecting to region %s', None)
        ] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:22,代码来源:test_checker.py

示例2: test_check_version_not_old

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_check_version_not_old(self):
        with patch.multiple(
            'awslimitchecker.checker',
            logger=DEFAULT,
            _get_version_info=DEFAULT,
            TrustedAdvisor=DEFAULT,
            _get_latest_version=DEFAULT,
            autospec=True,
        ) as mocks:
            mocks['_get_version_info'].return_value = self.mock_ver_info
            mocks['_get_latest_version'].return_value = None
            AwsLimitChecker()
        assert mocks['_get_latest_version'].mock_calls == [call()]
        assert mocks['logger'].mock_calls == [
            call.debug('Connecting to region %s', None)
        ] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:18,代码来源:test_checker.py

示例3: test_find_usage

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_find_usage(self):
        """test find usage method calls other methods"""
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                _find_cluster_manual_snapshots=DEFAULT,
                _find_cluster_subnet_groups=DEFAULT,
            ) as mocks:
                cls = _RedshiftService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        for x in [
            '_find_cluster_manual_snapshots',
            '_find_cluster_subnet_groups',
        ]:
            assert mocks[x].mock_calls == [call()] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:23,代码来源:test_redshift.py

示例4: test_find_usage

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_find_usage(self):
        """test find usage method calls other methods"""
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                _find_usage_applications=DEFAULT,
                _find_usage_application_versions=DEFAULT,
                _find_usage_environments=DEFAULT,
            ) as mocks:
                cls = _ElasticBeanstalkService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        for x in [
            '_find_usage_applications',
            '_find_usage_application_versions',
            '_find_usage_environments',
        ]:
            assert mocks[x].mock_calls == [call()] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:25,代码来源:test_elasticbeanstalk.py

示例5: test_find_usage

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_find_usage(self):
        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                pb,
                autospec=True,
                _find_usage_apis=DEFAULT,
                _find_usage_api_keys=DEFAULT,
                _find_usage_certs=DEFAULT,
                _find_usage_plans=DEFAULT,
                _find_usage_vpc_links=DEFAULT
            ) as mocks:
                cls = _ApigatewayService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        assert mock_conn.mock_calls == []
        assert mocks['_find_usage_apis'].mock_calls == [call(cls)]
        assert mocks['_find_usage_api_keys'].mock_calls == [call(cls)]
        assert mocks['_find_usage_certs'].mock_calls == [call(cls)]
        assert mocks['_find_usage_plans'].mock_calls == [call(cls)]
        assert mocks['_find_usage_vpc_links'].mock_calls == [call(cls)] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:26,代码来源:test_apigateway.py

示例6: test_update_limits_from_api

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_update_limits_from_api(self):
        """test _update_limits_from_api method calls other methods"""

        mock_conn = Mock()
        with patch('%s.connect' % pb) as mock_connect:
            with patch.multiple(
                    pb,
                    _find_limit_hosted_zone=DEFAULT,
            ) as mocks:
                cls = _Route53Service(21, 43, {}, None)
                cls.conn = mock_conn
                cls._update_limits_from_api()
        assert mock_connect.mock_calls == [call()]
        assert mock_conn.mock_calls == []
        for x in [
            '_find_limit_hosted_zone',
        ]:
            assert mocks[x].mock_calls == [call()] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:20,代码来源:test_route53.py

示例7: test_find_usage

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_find_usage(self):
        mock_conn = Mock()

        with patch('%s.connect' % self.pb) as mock_connect:
            with patch.multiple(
                    self.pb,
                    _find_usage_instances=DEFAULT,
                    _find_usage_subnet_groups=DEFAULT,
                    _find_usage_security_groups=DEFAULT,
                    _update_limits_from_api=DEFAULT,
            ) as mocks:
                cls = _RDSService(21, 43, {}, None)
                cls.conn = mock_conn
                assert cls._have_usage is False
                cls.find_usage()
        assert mock_connect.mock_calls == [call()]
        assert cls._have_usage is True
        for x in [
                '_find_usage_instances',
                '_find_usage_subnet_groups',
                '_find_usage_security_groups',
                '_update_limits_from_api',
        ]:
            assert mocks[x].mock_calls == [call()] 
开发者ID:jantman,项目名称:awslimitchecker,代码行数:26,代码来源:test_rds.py

示例8: test_healthcheck_return_200_even_if_some_servers_are_down

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_healthcheck_return_200_even_if_some_servers_are_down(self):
        marathon_addresses = [
            "http://invalid-host:8080",
            "http://172.30.0.1:8080",
            "http://172.31.0.1:8080",
        ]
        with application.test_client() as client, RequestsMock() as rsps, patch.multiple(
            conf, MARATHON_ADDRESSES=marathon_addresses
        ), patch.multiple(
            conf, MARATHON_LEADER=marathon_addresses[1]
        ):
            rsps.add(
                "GET",
                url=marathon_addresses[2] + "/ping",
                status=200,
                body="pong",
            )

            response = client.get("/healthcheck")
            self.assertEqual(200, response.status_code) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:22,代码来源:test_healthcheck.py

示例9: stub_netifaces

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def stub_netifaces():
    methods = {
        "interfaces": Mock(return_value=["eth0"]),
        "ifaddresses": Mock(
            return_value={
                netifaces.AF_INET: [
                    {
                        "addr": "10.0.10.1",
                        "netmask": "255.255.255.0",
                        "broadcast": "10.0.10.255",
                    },
                    {"addr": "127.0.0.1", "netmask": "255.0.0.0",},
                ]
            }
        ),
    }

    with patch.multiple("netifaces", **methods):
        yield 
开发者ID:postlund,项目名称:pyatv,代码行数:21,代码来源:conftest.py

示例10: test_matrix_lister_smoke_test

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_matrix_lister_smoke_test(get_accounts, get_private_key):
    (c1,) = get_accounts(1)
    client_mock = Mock()
    client_mock.api.base_url = "http://example.com"
    client_mock.user_id = "1"

    with patch.multiple(
        "raiden_libs.matrix",
        make_client=Mock(return_value=client_mock),
        join_broadcast_room=Mock(),
    ):
        listener = MatrixListener(
            private_key=get_private_key(c1),
            chain_id=ChainID(61),
            service_room_suffix="_service",
            message_received_callback=lambda _: None,
        )
        listener._run()  # pylint: disable=protected-access

    assert listener.startup_finished.done() 
开发者ID:raiden-network,项目名称:raiden-services,代码行数:22,代码来源:test_matrix.py

示例11: test_env_only_calls_get

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_env_only_calls_get():
    """Call only get."""
    context = Context({
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3',
        'env': {'get': {
            'key2': 'ARB_GET_ME1',
            'key4': 'ARB_GET_ME2'
        }}
    })

    with patch.multiple('pypyr.steps.env',
                        env_get=DEFAULT,
                        env_set=DEFAULT,
                        env_unset=DEFAULT
                        ) as mock_env:
        pypyr.steps.env.run_step(context)

    mock_env['env_get'].assert_called_once()
    mock_env['env_set'].assert_called_once()
    mock_env['env_unset'].assert_called_once() 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:24,代码来源:env_test.py

示例12: test_env_only_calls_set

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_env_only_calls_set():
    """Call only set."""
    context = Context({
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3',
        'env': {'set': {
            'ARB_SET_ME1': 'key2',
            'ARB_SET_ME2': 'key1'
        }}
    })

    with patch.multiple('pypyr.steps.env',
                        env_get=DEFAULT,
                        env_set=DEFAULT,
                        env_unset=DEFAULT
                        ) as mock_env:
        pypyr.steps.env.run_step(context)

    mock_env['env_get'].assert_called_once()
    mock_env['env_set'].assert_called_once()
    mock_env['env_unset'].assert_called_once() 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:24,代码来源:env_test.py

示例13: test_env_only_calls_unset

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_env_only_calls_unset():
    """Call only unset."""
    context = Context({
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3',
        'env': {'unset': [
            'ARB_DELETE_ME1',
            'ARB_DELETE_ME2'
        ]}
    })

    with patch.multiple('pypyr.steps.env',
                        env_get=DEFAULT,
                        env_set=DEFAULT,
                        env_unset=DEFAULT
                        ) as mock_env:
        pypyr.steps.env.run_step(context)

    mock_env['env_get'].assert_called_once()
    mock_env['env_set'].assert_called_once()
    mock_env['env_unset'].assert_called_once() 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:24,代码来源:env_test.py

示例14: test_tar_only_calls_extract

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_tar_only_calls_extract():
    """Only calls extract if only extract specified."""
    context = Context({
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3',
        'tar': {'extract': [
            {'in': 'key2',
             'out': 'ARB_GET_ME1'},
            {'in': 'key4',
             'out': 'ARB_GET_ME2'}
        ]}
    })

    with patch.multiple('pypyr.steps.tar',
                        tar_archive=DEFAULT,
                        tar_extract=DEFAULT
                        ) as mock_tar:
        pypyr.steps.tar.run_step(context)

    mock_tar['tar_extract'].assert_called_once()
    mock_tar['tar_archive'].assert_not_called() 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:24,代码来源:tar_test.py

示例15: test_tar_only_calls_archive

# 需要导入模块: from unittest.mock import patch [as 别名]
# 或者: from unittest.mock.patch import multiple [as 别名]
def test_tar_only_calls_archive():
    """Only calls archive if only archive specified."""
    context = Context({
        'key1': 'value1',
        'key2': 'value2',
        'key3': 'value3',
        'tar': {'archive': [
            {'in': 'key2',
             'out': 'ARB_GET_ME1'},
            {'in': 'key4',
             'out': 'ARB_GET_ME2'}
        ]}
    })

    with patch.multiple('pypyr.steps.tar',
                        tar_archive=DEFAULT,
                        tar_extract=DEFAULT
                        ) as mock_tar:
        pypyr.steps.tar.run_step(context)

    mock_tar['tar_extract'].assert_not_called()
    mock_tar['tar_archive'].assert_called_once() 
开发者ID:pypyr,项目名称:pypyr-cli,代码行数:24,代码来源:tar_test.py


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