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


Python mock.sentinel方法代码示例

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


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

示例1: test__compute_snapshot_deletes_w_real_comparator

# 需要导入模块: import mock [as 别名]
# 或者: from mock import sentinel [as 别名]
def test__compute_snapshot_deletes_w_real_comparator(self):
        from google.cloud.firestore_v1.watch import WatchDocTree

        doc_tree = WatchDocTree()

        class DummyDoc(object):
            update_time = mock.sentinel

        deleted_doc_1 = DummyDoc()
        deleted_doc_2 = DummyDoc()
        doc_tree = doc_tree.insert(deleted_doc_1, None)
        doc_tree = doc_tree.insert(deleted_doc_2, None)
        doc_map = {"/deleted_1": deleted_doc_1, "/deleted_2": deleted_doc_2}
        delete_changes = ["/deleted_1", "/deleted_2"]
        add_changes = []
        update_changes = []
        inst = self._makeOne(comparator=object())
        updated_tree, updated_map, applied_changes = inst._compute_snapshot(
            doc_tree, doc_map, delete_changes, add_changes, update_changes
        )
        self.assertEqual(updated_map, {}) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:23,代码来源:test_watch.py

示例2: test_read_pod_logs_successfully_with_tail_lines

# 需要导入模块: import mock [as 别名]
# 或者: from mock import sentinel [as 别名]
def test_read_pod_logs_successfully_with_tail_lines(self):
        mock.sentinel.metadata = mock.MagicMock()
        self.mock_kube_client.read_namespaced_pod_log.side_effect = [
            mock.sentinel.logs
        ]
        logs = self.pod_launcher.read_pod_logs(mock.sentinel, 100)
        self.assertEqual(mock.sentinel.logs, logs)
        self.mock_kube_client.read_namespaced_pod_log.assert_has_calls([
            mock.call(
                _preload_content=False,
                container='base',
                follow=True,
                name=mock.sentinel.metadata.name,
                namespace=mock.sentinel.metadata.namespace,
                tail_lines=100
            ),
        ]) 
开发者ID:apache,项目名称:airflow,代码行数:19,代码来源:test_pod_launcher.py

示例3: test_get_service_handle

# 需要导入模块: import mock [as 别名]
# 或者: from 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)]) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:19,代码来源:test_windows.py

示例4: test_create_service

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:test_windows.py

示例5: test_set_service_credentials

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:19,代码来源:test_windows.py

示例6: test__get_forward_table_insufficient_buffer_no_memory

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:20,代码来源:test_windows.py

示例7: test_execute_process_as_user_fail

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:22,代码来源:test_windows.py

示例8: _test_enum_users

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:19,代码来源:test_windows.py

示例9: _test_set_path_admin_acls

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:23,代码来源:test_windows.py

示例10: _test_take_path_ownership

# 需要导入模块: import mock [as 别名]
# 或者: from 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) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:test_windows.py

示例11: _test_get_ephemeral_disk_volume_by_label

# 需要导入模块: import mock [as 别名]
# 或者: from 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)) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:test_ephemeraldisk.py

示例12: _test_set_ephemeral_disk_data_loss_warning

# 需要导入模块: import mock [as 别名]
# 或者: from 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') 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:test_ephemeraldisk.py

示例13: test_arista_instance_with_proper_transport

# 需要导入模块: import mock [as 别名]
# 或者: from mock import sentinel [as 别名]
def test_arista_instance_with_proper_transport(self):
        pyeapi_client_node = mock.sentinel

        flexmock(pyeapi).should_receive('connect').once() \
            .with_args(host="1.2.3.4",
                       username="you sir name",
                       password="paw sword",
                       port=8888,
                       transport="trololo",
                       return_node=True,
                       timeout=300) \
            .and_return(pyeapi_client_node)

        switch = Arista(
            SwitchDescriptor(model='arista',
                             hostname="1.2.3.4",
                             username="you sir name",
                             password="paw sword",
                             port=8888),
            transport="trololo"
        )

        switch._connect()

        assert_that(switch.node, is_(pyeapi_client_node)) 
开发者ID:internap,项目名称:netman,代码行数:27,代码来源:arista_test.py

示例14: test_arista_uses_command_timeout

# 需要导入模块: import mock [as 别名]
# 或者: from mock import sentinel [as 别名]
def test_arista_uses_command_timeout(self):
        arista.default_command_timeout = 500

        pyeapi_client_node = mock.sentinel

        flexmock(pyeapi).should_receive('connect').once() \
            .with_args(host="1.2.3.4",
                       username=None,
                       password=None,
                       port=None,
                       transport="trololo",
                       return_node=True,
                       timeout=500) \
            .and_return(pyeapi_client_node)

        switch = Arista(
            SwitchDescriptor(model='arista',
                             hostname="1.2.3.4"),
            transport="trololo"
        )

        switch._connect() 
开发者ID:internap,项目名称:netman,代码行数:24,代码来源:arista_test.py

示例15: test__compute_snapshot_operation_relative_ordering

# 需要导入模块: import mock [as 别名]
# 或者: from mock import sentinel [as 别名]
def test__compute_snapshot_operation_relative_ordering(self):
        from google.cloud.firestore_v1.watch import WatchDocTree

        doc_tree = WatchDocTree()

        class DummyDoc(object):
            update_time = mock.sentinel

        deleted_doc = DummyDoc()
        added_doc = DummyDoc()
        added_doc._document_path = "/added"
        updated_doc = DummyDoc()
        updated_doc._document_path = "/updated"
        doc_tree = doc_tree.insert(deleted_doc, None)
        doc_tree = doc_tree.insert(updated_doc, None)
        doc_map = {"/deleted": deleted_doc, "/updated": updated_doc}
        added_snapshot = DummyDocumentSnapshot(added_doc, None, True, None, None, None)
        added_snapshot.reference = added_doc
        updated_snapshot = DummyDocumentSnapshot(
            updated_doc, None, True, None, None, None
        )
        updated_snapshot.reference = updated_doc
        delete_changes = ["/deleted"]
        add_changes = [added_snapshot]
        update_changes = [updated_snapshot]
        inst = self._makeOne()
        updated_tree, updated_map, applied_changes = inst._compute_snapshot(
            doc_tree, doc_map, delete_changes, add_changes, update_changes
        )
        # TODO: Verify that the assertion here is correct.
        self.assertEqual(
            updated_map, {"/updated": updated_snapshot, "/added": added_snapshot}
        ) 
开发者ID:googleapis,项目名称:python-firestore,代码行数:35,代码来源:test_watch.py


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