當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。