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


Python mock.DEFAULT属性代码示例

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


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

示例1: _patch_object

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def _patch_object(
    target,
    attribute,
    new=mock.DEFAULT,
    spec=None,
    create=False,
    mocksignature=False,
    spec_set=None,
    autospec=False,
    new_callable=None,
    **kwargs
):
    getter = lambda: target
    return _make_patch_async(
        getter,
        attribute,
        new,
        spec,
        create,
        mocksignature,
        spec_set,
        autospec,
        new_callable,
        kwargs,
    ) 
开发者ID:quora,项目名称:asynq,代码行数:27,代码来源:mock_.py

示例2: test_delete_port

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_delete_port(self):
        PORT_ID = uuidutils.generate_uuid()

        self.driver.neutron_client.delete_port.side_effect = [
            mock.DEFAULT, neutron_exceptions.NotFound, Exception('boom')]

        # Test successful delete
        self.driver.delete_port(PORT_ID)

        self.driver.neutron_client.delete_port.assert_called_once_with(PORT_ID)

        # Test port NotFound (does not raise)
        self.driver.delete_port(PORT_ID)

        # Test unknown exception
        self.assertRaises(exceptions.NetworkServiceError,
                          self.driver.delete_port, PORT_ID) 
开发者ID:openstack,项目名称:octavia,代码行数:19,代码来源:test_allowed_address_pairs.py

示例3: test_set_port_admin_state_up

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_set_port_admin_state_up(self):
        PORT_ID = uuidutils.generate_uuid()
        TEST_STATE = 'test state'

        self.driver.neutron_client.update_port.side_effect = [
            mock.DEFAULT, neutron_exceptions.NotFound, Exception('boom')]

        # Test successful state set
        self.driver.set_port_admin_state_up(PORT_ID, TEST_STATE)

        self.driver.neutron_client.update_port.assert_called_once_with(
            PORT_ID, {'port': {'admin_state_up': TEST_STATE}})

        # Test port NotFound
        self.assertRaises(network_base.PortNotFound,
                          self.driver.set_port_admin_state_up,
                          PORT_ID, {'port': {'admin_state_up': TEST_STATE}})

        # Test unknown exception
        self.assertRaises(exceptions.NetworkServiceError,
                          self.driver.set_port_admin_state_up, PORT_ID,
                          {'port': {'admin_state_up': TEST_STATE}}) 
开发者ID:openstack,项目名称:octavia,代码行数:24,代码来源:test_allowed_address_pairs.py

示例4: test_check_version_old

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例5: test_check_version_not_old

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例6: test_find_usage

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例7: test_find_usage

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例8: test_find_usage

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例9: test_update_limits_from_api

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例10: test_find_usage

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [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

示例11: test_attach_volume_fail

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_attach_volume_fail(self, mock_execute):
        fake_key = 'ea6c2e1b8f7f4f84ae3560116d659ba2'
        self.encryptor._get_key = mock.MagicMock()
        self.encryptor._get_key.return_value = (
            test_cryptsetup.fake__get_key(None, fake_key))

        mock_execute.side_effect = [
            putils.ProcessExecutionError(exit_code=1),  # luksOpen
            mock.DEFAULT,  # isLuks
        ]

        self.assertRaises(putils.ProcessExecutionError,
                          self.encryptor.attach_volume, None)

        mock_execute.assert_has_calls([
            mock.call('cryptsetup', 'luksOpen', '--key-file=-', self.dev_path,
                      self.dev_name, process_input=fake_key,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=True),
            mock.call('cryptsetup', 'isLuks', '--verbose', self.dev_path,
                      root_helper=self.root_helper,
                      run_as_root=True, check_exit_code=True),
        ], any_order=False) 
开发者ID:openstack,项目名称:os-brick,代码行数:25,代码来源:test_luks.py

示例12: test_listener_process_event_task

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_listener_process_event_task(listener):
    with mock.patch.multiple(listener, _set_task_event=DEFAULT,
                             _set_worker_event=DEFAULT, _set_custom_event=DEFAULT) as mtw, \
            mock.patch('clearly.server.event_listener.obj_to_message') as otm:
        mtw['_set_task_event'].return_value = (x for x in chain(('obj',), 'abc'))

        # noinspection PyProtectedMember
        listener._process_event(dict(type='task-anything'))

    mtw['_set_task_event'].assert_called_once_with(dict(type='task-anything'))
    for k in '_set_worker_event', '_set_custom_event':
        mtw[k].assert_not_called()
    assert listener.queue_tasks.qsize() == 3
    assert listener.queue_workers.qsize() == 0
    assert otm.call_args_list == [
        call('obj', TaskMessage, state='a'),
        call('obj', TaskMessage, state='b'),
        call('obj', TaskMessage, state='c'),
    ] 
开发者ID:rsalmei,项目名称:clearly,代码行数:21,代码来源:test_event_listener.py

示例13: test_listener_process_event_worker

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_listener_process_event_worker(listener):
    with mock.patch.multiple(listener, _set_task_event=DEFAULT,
                             _set_worker_event=DEFAULT, _set_custom_event=DEFAULT) as mtw, \
            mock.patch('clearly.server.event_listener.obj_to_message') as otm:
        mtw['_set_worker_event'].return_value = (x for x in ('obj', 'ok'))

        # noinspection PyProtectedMember
        listener._process_event(dict(type='worker-anything'))

    mtw['_set_worker_event'].assert_called_once_with(dict(type='worker-anything'))
    for k in '_set_task_event', '_set_custom_event':
        mtw[k].assert_not_called()
    assert listener.queue_workers.qsize() == 1
    assert listener.queue_tasks.qsize() == 0
    assert otm.call_args_list == [
        call('obj', WorkerMessage, state='ok'),
    ] 
开发者ID:rsalmei,项目名称:clearly,代码行数:19,代码来源:test_event_listener.py

示例14: test_connect__multiple_amqp_init_errors

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_connect__multiple_amqp_init_errors(self, sleep, chan, conn):
        # Prepare test
        conn.side_effect = [
            RecoverableConnectionError('connection already closed'),
            ValueError("Must supply authentication or userid/password"),
            ValueError("Invalid login method", 'login_method'),
            DEFAULT
        ]
        # Execute test
        ok = self.hc.connect()
        # Evaluate results
        expected = [call(self.hc.host, userid=self.hc.user, password=self.hc.password, virtual_host=self.hc.vhost,
                         ssl=self.hc.ssl)]*4 + [call().connect(), call().channel()]
        self.assertEqual(expected, conn.mock_calls, self.amqp_connection_assert_msg)
        expected = [call(2), call(4), call(8)]
        self.assertEqual(expected, sleep.mock_calls)
        self.assertTrue(ok)
        self.assertIsNotNone(self.hc.connection)
        self.assertIsNotNone(self.hc.channel)
        self.assertEqual(1, len(self.hc.toclose))
        self.assertErrorInLog() 
开发者ID:MetPX,项目名称:sarracenia,代码行数:23,代码来源:test_sr_amqp.py

示例15: test_connect__multiple_amqp_connect_errors

# 需要导入模块: from unittest import mock [as 别名]
# 或者: from unittest.mock import DEFAULT [as 别名]
def test_connect__multiple_amqp_connect_errors(self, sleep, chan, conn):
        # Prepare test
        conn.return_value = conn
        conn.connect.side_effect = [
            AMQPError(self.AMQPError_msg),
            SSLError('SSLError stub'),
            IOError('IOError stub'),
            OSError('OSError stub'),
            Exception(self.Exception_msg),
            DEFAULT
        ]
        # Execute test
        ok = self.hc.connect()
        # Evaluate results
        expected = [call(self.hc.host, userid=self.hc.user, password=self.hc.password, virtual_host=self.hc.vhost,
                         ssl=self.hc.ssl), call.connect()]*6 + [call.channel()]
        self.assertEqual(expected, conn.mock_calls, self.amqp_connection_assert_msg)
        expected = [call(2), call(4), call(8), call(16), call(32)]
        self.assertEqual(expected, sleep.mock_calls, self.sleep_assert_msg)
        self.assertTrue(ok)
        self.assertIsNotNone(self.hc.connection)
        self.assertIsNotNone(self.hc.channel)
        self.assertEqual(1, len(self.hc.toclose))
        self.assertErrorInLog() 
开发者ID:MetPX,项目名称:sarracenia,代码行数:26,代码来源:test_sr_amqp.py


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