本文整理匯總了Python中unittest.mock.sentinel方法的典型用法代碼示例。如果您正苦於以下問題:Python mock.sentinel方法的具體用法?Python mock.sentinel怎麽用?Python mock.sentinel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類unittest.mock
的用法示例。
在下文中一共展示了mock.sentinel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_acquire_service_pub_ip_info_usr_specified_ip
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_acquire_service_pub_ip_info_usr_specified_ip(self):
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
m_driver = mock.Mock(spec=cls)
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
os_net = self.useFixture(k_fix.MockNetworkClient()).client
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
'port_id': None,
'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'})
os_net.ips.return_value = (ip for ip in [fip])
project_id = mock.sentinel.project_id
spec_type = 'LoadBalancer'
spec_lb_ip = '1.2.3.4'
expected_resp = (obj_lbaas
.LBaaSPubIp(ip_id=fip.id,
ip_addr=fip.floating_ip_address,
alloc_method='user'))
result = cls.acquire_service_pub_ip_info(m_driver, spec_type,
spec_lb_ip, project_id)
self.assertEqual(result, expected_resp)
示例2: test_acquire_service_pub_ip_info_user_specified_non_exist_fip
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_acquire_service_pub_ip_info_user_specified_non_exist_fip(self):
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
m_driver = mock.Mock(spec=cls)
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
os_net = self.useFixture(k_fix.MockNetworkClient()).client
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
'port_id': None})
os_net.ips.return_value = (ip for ip in [fip])
project_id = mock.sentinel.project_id
spec_type = 'LoadBalancer'
spec_lb_ip = '1.2.3.4'
result = cls.acquire_service_pub_ip_info(m_driver, spec_type,
spec_lb_ip, project_id)
self.assertIsNone(result)
示例3: test_acquire_service_pub_ip_info_user_specified_occupied_fip
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_acquire_service_pub_ip_info_user_specified_occupied_fip(self):
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
m_driver = mock.Mock(spec=cls)
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
os_net = self.useFixture(k_fix.MockNetworkClient()).client
fip = munch.Munch({'floating_ip_address': '1.2.3.4',
'port_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
os_net.ips.return_value = (ip for ip in [fip])
project_id = mock.sentinel.project_id
spec_type = 'LoadBalancer'
spec_lb_ip = '1.2.3.4'
result = cls.acquire_service_pub_ip_info(m_driver, spec_type,
spec_lb_ip, project_id)
self.assertIsNone(result)
示例4: test_acquire_service_pub_ip_info_alloc_from_pool
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_acquire_service_pub_ip_info_alloc_from_pool(self, m_cfg):
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
m_driver = mock.Mock(spec=cls)
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
os_net = self.useFixture(k_fix.MockNetworkClient()).client
m_cfg.neutron_defaults.external_svc_subnet = (mock.sentinel
.external_svc_subnet)
os_net.get_subnet.return_value = munch.Munch(
{'network_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'})
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
os_net.create_ip.return_value = fip
project_id = mock.sentinel.project_id
spec_type = 'LoadBalancer'
spec_lb_ip = None
expected_resp = obj_lbaas.LBaaSPubIp(ip_id=fip.id,
ip_addr=fip.floating_ip_address,
alloc_method='pool')
result = cls.acquire_service_pub_ip_info(m_driver, spec_type,
spec_lb_ip, project_id)
self.assertEqual(result, expected_resp)
示例5: test_get_service_handle
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_get_service_handle(self):
open_scm = self._win32service_mock.OpenSCManager
open_scm.return_value = mock.sentinel.hscm
open_service = self._win32service_mock.OpenService
open_service.return_value = mock.sentinel.hs
close_service = self._win32service_mock.CloseServiceHandle
args = ("fake_name", mock.sentinel.service_access,
mock.sentinel.scm_access)
with self._winutils._get_service_handle(*args) as hs:
self.assertIs(hs, mock.sentinel.hs)
open_scm.assert_called_with(None, None, mock.sentinel.scm_access)
open_service.assert_called_with(mock.sentinel.hscm, "fake_name",
mock.sentinel.service_access)
close_service.assert_has_calls([mock.call(mock.sentinel.hs),
mock.call(mock.sentinel.hscm)])
示例6: test_create_service
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_create_service(self, mock_get_service_control_manager):
mock_hs = mock.MagicMock()
mock_service_name = "fake name"
mock_start_mode = "Automatic"
mock_display_name = mock.sentinel.mock_display_name
mock_path = mock.sentinel.path
mock_get_service_control_manager.return_value = mock_hs
with self.snatcher:
self._winutils.create_service(mock_service_name,
mock_display_name,
mock_path,
mock_start_mode)
self.assertEqual(["Creating service fake name"],
self.snatcher.output)
mock_get_service_control_manager.assert_called_once_with(
scm_access=self._win32service_mock.SC_MANAGER_CREATE_SERVICE)
self._win32service_mock.CreateService.assert_called_once_with(
mock_hs.__enter__(), mock_service_name, mock_display_name,
self._win32service_mock.SERVICE_ALL_ACCESS,
self._win32service_mock.SERVICE_WIN32_OWN_PROCESS,
self._win32service_mock.SERVICE_AUTO_START,
self._win32service_mock.SERVICE_ERROR_NORMAL,
mock_path, None, False, None, None, None)
示例7: test_set_service_credentials
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_set_service_credentials(self, mock_get_service):
self._win32service_mock.SERVICE_CHANGE_CONFIG = mock.sentinel.change
self._win32service_mock.SERVICE_NO_CHANGE = mock.sentinel.no_change
mock_change_service = self._win32service_mock.ChangeServiceConfig
mock_context_manager = mock.MagicMock()
mock_context_manager.__enter__.return_value = mock.sentinel.hs
mock_get_service.return_value = mock_context_manager
self._winutils.set_service_credentials(
mock.sentinel.service, mock.sentinel.user, mock.sentinel.password)
mock_get_service.assert_called_with(mock.sentinel.service,
mock.sentinel.change)
mock_change_service.assert_called_with(
mock.sentinel.hs, mock.sentinel.no_change, mock.sentinel.no_change,
mock.sentinel.no_change, None, None, False, None,
mock.sentinel.user, mock.sentinel.password, None)
示例8: test__get_forward_table_insufficient_buffer_no_memory
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test__get_forward_table_insufficient_buffer_no_memory(self):
self._kernel32.HeapAlloc.side_effect = (mock.sentinel.table_mem, None)
self._iphlpapi.GetIpForwardTable.return_value = (
self._winutils.ERROR_INSUFFICIENT_BUFFER)
with self.assertRaises(exception.CloudbaseInitException):
with self._winutils._get_forward_table():
pass
table = self._ctypes_mock.cast.return_value
self._iphlpapi.GetIpForwardTable.assert_called_once_with(
table,
self._ctypes_mock.byref.return_value, 0)
heap_calls = [
mock.call(self._kernel32.GetProcessHeap.return_value, 0, table),
mock.call(self._kernel32.GetProcessHeap.return_value, 0, table)
]
self.assertEqual(heap_calls, self._kernel32.HeapFree.mock_calls)
示例9: test_execute_process_as_user_fail
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_execute_process_as_user_fail(self, mock_list2cmdline,
mock_proc_info, mock_startup_info):
advapi32 = self._windll_mock.advapi32
advapi32.CreateProcessAsUserW.side_effect = [False, True]
kernel32 = self._ctypes_mock.windll.kernel32
kernel32.GetExitCodeProcess.return_value = False
mock_proc_info.hProcess = True
token = mock.sentinel.token
args = mock.sentinel.args
new_console = mock.sentinel.new_console
with self.assert_raises_windows_message("CreateProcessAsUserW "
"failed: %r", 100):
self._winutils.execute_process_as_user(token, args, False,
new_console)
with self.assert_raises_windows_message("GetExitCodeProcess "
"failed: %r", 100):
self._winutils.execute_process_as_user(token, args, True,
new_console)
示例10: _test_enum_users
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def _test_enum_users(self, resume_handle=False, exc=None):
userenum_mock = self._win32net_mock.NetUserEnum
if exc is not None:
userenum_mock.side_effect = [exc]
with self.assertRaises(exception.CloudbaseInitException):
self._winutils.enum_users()
return
else:
userenum_mock.side_effect = (
[([{"name": "fake name"}], mock.sentinel, False)] * 3 +
[([{"name": "fake name"}], mock.sentinel, resume_handle)])
self._winutils.enum_users()
result = self._winutils.enum_users()
if resume_handle:
self.assertEqual(result, ["fake name"] * 3)
示例11: _test_set_path_admin_acls
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def _test_set_path_admin_acls(self, mock_execute_system32_process,
ret_val=None):
mock_path = mock.sentinel.path
expected_logging = ["Assigning admin ACLs on path: %s" % mock_path]
expected_call = [
"icacls.exe", mock_path, "/inheritance:r", "/grant:r",
"*S-1-5-18:(OI)(CI)F", "*S-1-5-32-544:(OI)(CI)F"]
mock_execute_system32_process.return_value = (
mock.sentinel.out,
mock.sentinel.err,
ret_val)
with self.snatcher:
if ret_val:
self.assertRaises(
exception.CloudbaseInitException,
self._winutils.set_path_admin_acls,
mock_path)
else:
self._winutils.set_path_admin_acls(mock_path)
self.assertEqual(self.snatcher.output, expected_logging)
mock_execute_system32_process.assert_called_once_with(expected_call)
示例12: _test_take_path_ownership
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def _test_take_path_ownership(self, mock_execute_system32_process,
ret_val=None, username=None):
mock_path = mock.sentinel.path
expected_logging = ["Taking ownership of path: %s" % mock_path]
expected_call = ["takeown.exe", "/F", mock_path]
mock_execute_system32_process.return_value = (
mock.sentinel.out,
mock.sentinel.err,
ret_val)
if username:
self.assertRaises(
NotImplementedError, self._winutils.take_path_ownership,
mock_path, username)
return
with self.snatcher:
if ret_val:
self.assertRaises(
exception.CloudbaseInitException,
self._winutils.take_path_ownership,
mock_path, username)
else:
self._winutils.take_path_ownership(mock_path, username)
self.assertEqual(self.snatcher.output, expected_logging)
mock_execute_system32_process.assert_called_once_with(expected_call)
示例13: _test_get_ephemeral_disk_volume_by_label
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def _test_get_ephemeral_disk_volume_by_label(self, label,
ephemeral_disk_volume_label):
expected_result = None
mock_osutils = mock.MagicMock()
if ephemeral_disk_volume_label:
labels = [None, str(mock.sentinel.label)] * 2
labels += [label] + [None, str(mock.sentinel.label)]
mock_osutils.get_logical_drives.return_value = range(len(labels))
mock_osutils.get_volume_label.side_effect = labels
if label.upper() == ephemeral_disk_volume_label.upper():
expected_result = labels.index(label)
with testutils.ConfPatcher('ephemeral_disk_volume_label',
ephemeral_disk_volume_label):
result = self._disk._get_ephemeral_disk_volume_by_label(
mock_osutils)
self.assertEqual(result, expected_result)
if ephemeral_disk_volume_label:
mock_osutils.get_logical_drives.assert_called_once_with()
if expected_result is not None:
self.assertEqual(mock_osutils.get_volume_label.call_count,
expected_result + 1)
else:
self.assertEqual(mock_osutils.get_volume_label.call_count,
len(labels))
示例14: _test_set_ephemeral_disk_data_loss_warning
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def _test_set_ephemeral_disk_data_loss_warning(self, exception_raised):
mock_service = mock.MagicMock()
disk_warning_path = str(mock.sentinel.disk_warning_path)
expected_logging = [
"Setting ephemeral disk data loss warning: %s" % disk_warning_path
]
if exception_raised:
eclass = metadata_services_base.NotExistingMetadataException
mock_service.get_ephemeral_disk_data_loss_warning.side_effect = \
eclass
expected_logging += [
"Metadata service does not provide an ephemeral "
"disk data loss warning content"
]
else:
mock_service.get_ephemeral_disk_data_loss_warning.return_value = \
str(mock.sentinel.data_loss_warning)
with testutils.LogSnatcher(MODULE_PATH) as snatcher:
with mock.patch(MODULE_PATH + '.open', mock.mock_open(),
create=True) as mock_open:
self._disk._set_ephemeral_disk_data_loss_warning(
mock_service, disk_warning_path)
self.assertEqual(snatcher.output, expected_logging)
mock_open.assert_called_once_with(disk_warning_path, 'wb')
示例15: test_force_close
# 需要導入模塊: from unittest import mock [as 別名]
# 或者: from unittest.mock import sentinel [as 別名]
def test_force_close(self):
tr = self.create_transport()
tr._buffer.extend(b'1')
self.loop.add_reader(7, mock.sentinel)
self.loop.add_writer(7, mock.sentinel)
tr._force_close(None)
self.assertTrue(tr.is_closing())
self.assertEqual(tr._buffer, list_to_buffer())
self.assertFalse(self.loop.readers)
self.assertFalse(self.loop.writers)
# second close should not remove reader
tr._force_close(None)
self.assertFalse(self.loop.readers)
self.assertEqual(1, self.loop.remove_reader_count[7])