本文整理匯總了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,
)
示例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)
示例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}})
示例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)
]
示例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)
]
示例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()]
示例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()]
示例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)]
示例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()]
示例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()]
示例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)
示例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'),
]
示例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'),
]
示例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()
示例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()