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


Python MagicMock.configure_mock方法代码示例

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


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

示例1: test_filemetadata_read_metadata

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_filemetadata_read_metadata(self, m_img_md):
        """
        Test read_metadata() method with mocked pyexiv2.ImageMetadata object.
        Mock keys expected and __getitem__ to return some value. Confirm
        expected value is returned.
        """
        exif_keys = ['Exif.Image.DateTime']
        xmp_keys = ['Xmp.xmp.CreateDate']
        attrs = {
            # Return exif_keys
            'exif_keys': exif_keys,
            # Return xmp_keys
            'xmp_keys': xmp_keys,
            # Return 1 for everything?
            '__getitem__.return_value': Mock(raw_value=1),
        }
        # Create a mock that will return meaningful values for testing the
        # unit.
        m_keys = MagicMock()
        m_keys.configure_mock(**attrs)

        # Return the mock when pyexiv2.ImageMetadata(src_fn) is called.
        m_img_md.return_value = m_keys

        # Instantiate with any filename. Mock prevents read.
        filemd = FileMetadata("file.jpg")

        expected_metadata = {exif_keys[0]: 1, xmp_keys[0]: 1}
        assert filemd.read_metadata() == expected_metadata
开发者ID:eigenholser,项目名称:jpeg_rename,代码行数:31,代码来源:test_filemetadata_read_metadata.py

示例2: test_copy_metadata_main_missing_directory

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_copy_metadata_main_missing_directory(self, m_logger, m_exit,
            m_exists, m_isdir, m_process_all_files, m_argparser):
        """
        Test main() function. Mock CustomArgumentParser to return values
        desired for test but with missing `src_directory`. Verify correct
        behavior by asserting calls on logger, usage_message, and exit.
        """
        m_exists.return_value = True
        m_isdir.return_value = True

        # Mock up the proper return values.
        m_parse_args = MagicMock(
            src_directory=None,
            dst_directory="/def",
            simon_sez=True,
            verbose=False,
        )

        attrs = {
            'parse_args.return_value': m_parse_args,
            'usage_message.return_value': None,
        }

        # This one configured to return m_parse_args.
        m_parse_args_container = MagicMock()
        m_parse_args_container.configure_mock(**attrs)
        m_argparser.return_value = m_parse_args_container

        # Invoke the unit.
        retval = main()

        # Confirm expected behavior
        m_logger.error.assert_called()
        m_parse_args_container.usage_message.assert_called_once()
        m_exit.assert_called_once_with(1)
开发者ID:eigenholser,项目名称:jpeg_rename,代码行数:37,代码来源:test_copy_metadata_main.py

示例3: test_filemetadata_set_datetime_exception

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_filemetadata_set_datetime_exception(self,
         m_xmp_tag, m_exif_tag, m_img_md, m_logger, exception):
     """
     Test set_datetime() method with Exception raised on write() call.
     Verify exception handled by mocking logger and confirm
     called_once_with(exception). Also, just to be pedantic, verify
     img_md.write() called once.
     """
     new_datetime = datetime.now()
     # Raise this exception when write() called.
     md_attrs = {
         'write.side_effect': exception,
         '__getitem__.return_value': Mock(raw_value=1),
     }
     m_write = MagicMock()
     m_write.configure_mock(**md_attrs)
     m_img_md.return_value = m_write
     filemd = FileMetadata("file.jpg")
     filemd.metadata = {"One fish": "Two Fish"}
     # Will fall through and call filemd.img_md.write()...boom!
     filemd.set_datetime(new_datetime)
     # Confirm img_md.write() called.
     filemd.img_md.write.assert_called_once()
     # Confirm exception raised by proxy.
     m_logger.error.assert_called_once_with(exception)
开发者ID:eigenholser,项目名称:jpeg_rename,代码行数:27,代码来源:test_filemetadata_read_metadata.py

示例4: test_pass_check_package

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_pass_check_package(self, mock_popen):
     process_mock = MagicMock()
     attrs = {'communicate.return_value': ("", ""), 'returncode': 0}
     process_mock.configure_mock(**attrs)
     mock_popen.return_value = process_mock
     result = DebianDependencies._check_package("package")
     assert result is True
开发者ID:jgrycz,项目名称:study,代码行数:9,代码来源:test_debian_dependencies.py

示例5: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def setUp(self):
        crush_node_by_id = {-1:
                            {'name': 'root',
                             'type_name': 'root',
                             'items': [{'id': -3,
                                        'weight': 3,
                                        'pos': 1},
                                       {'id': -2,
                                        'weight': 2,
                                        'pos': 0}]
                             },
                            -2: {'name': 'rack1', 'items': []},
                            -4: {'name': 'rack3', 'items': []},
                            -3: {'name': 'rack2', 'items': []}}

        osd_map_attrs = {'get_tree_node': lambda x: crush_node_by_id[x],
                         'osd_tree_node_by_id': {2: {'name': 'osd.2'},
                                                 3: {'name': 'osd.3'}},
                         'parent_bucket_by_node_id': {-2: {'name': 'root', 'type': 'root'}},
                         'osds_by_id': {0: {'up': True}, 1: {'up': False}}}
        fake_osd_map = MagicMock()
        fake_osd_map.configure_mock(**osd_map_attrs)

        fake_cluster_monitor = MagicMock()
        attributes = {'name': 'I am a fake',
                      'fsid': 12345,
                      'get_sync_object.return_value': fake_osd_map}
        fake_cluster_monitor.configure_mock(**attributes)

        self.factory = CrushNodeRequestFactory(fake_cluster_monitor)
开发者ID:AnishSid,项目名称:calamari,代码行数:32,代码来源:test_crush_node_request_factory.py

示例6: test_changing_magic_set_in_initialization

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_changing_magic_set_in_initialization(self):
     m = MagicMock(**{'__str__.return_value': "12"})
     m.__str__.return_value = "13"
     self.assertEqual(str(m), "13")
     m = MagicMock(**{'__str__.return_value': "12"})
     m.configure_mock(**{'__str__.return_value': "14"})
     self.assertEqual(str(m), "14")
开发者ID:5m0k3r,项目名称:desarrollo_web_udp,代码行数:9,代码来源:testmagicmethods.py

示例7: test_translation_static_transcript_xml_with_data_dirc

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_translation_static_transcript_xml_with_data_dirc(self):
        """
        Test id data_dir is set in XML course.

        Set course data_dir and ensure we get redirected to that path
        if it isn't found in the contentstore.
        """
        # Simulate data_dir set in course.
        test_modulestore = MagicMock()
        attrs = {"get_course.return_value": Mock(data_dir="dummy/static", static_asset_path="")}
        test_modulestore.configure_mock(**attrs)
        self.item_descriptor.runtime.modulestore = test_modulestore

        # Test youtube style en
        request = Request.blank("/translation/en?videoId=12345")
        response = self.item.transcript(request=request, dispatch="translation/en")
        self.assertEqual(response.status, "307 Temporary Redirect")
        self.assertIn(("Location", "/static/dummy/static/subs_12345.srt.sjson"), response.headerlist)

        # Test HTML5 video style
        self.item.sub = "OEoXaMPEzfM"
        request = Request.blank("/translation/en")
        response = self.item.transcript(request=request, dispatch="translation/en")
        self.assertEqual(response.status, "307 Temporary Redirect")
        self.assertIn(("Location", "/static/dummy/static/subs_OEoXaMPEzfM.srt.sjson"), response.headerlist)

        # Test different language to ensure we are just ignoring it since we can't
        # translate with static fallback
        request = Request.blank("/translation/uk")
        response = self.item.transcript(request=request, dispatch="translation/uk")
        self.assertEqual(response.status, "404 Not Found")
开发者ID:DNFcode,项目名称:edx-platform,代码行数:33,代码来源:test_video_handlers.py

示例8: test_copy_metadata_main_path_not_exist

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_copy_metadata_main_path_not_exist(self, m_exit, m_exists,
            m_isdir, m_process_all_files, m_argparser):
        """
        Test main() function. Mock CustomArgumentParser to return values
        desired for test. Mock os.path.exists to return False. Verify
        usage_message() called once.
        """
        m_exists.return_value = False
        m_isdir.return_value = True

        # Mock up the proper return values.
        m_parse_args = MagicMock(
            src_directory="/abc",
            dst_directory="/def",
            simon_sez=True,
            verbose=False,
        )

        attrs = {
            'parse_args.return_value': m_parse_args,
            'usage_message.return_value': None,
        }

        # This one configured to return m_parse_args.
        m_parse_args_container = MagicMock()
        m_parse_args_container.configure_mock(**attrs)
        m_argparser.return_value = m_parse_args_container

        # Invoke the unit.
        retval = main()

        # Confirm expected behavior
        m_exit.assert_called_once_with(1)
        m_parse_args_container.usage_message.assert_called_once()
开发者ID:eigenholser,项目名称:jpeg_rename,代码行数:36,代码来源:test_copy_metadata_main.py

示例9: test_copy_metadata_main_args_with_verbose_params

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_copy_metadata_main_args_with_verbose_params(self,
            m_logging, m_exists, m_isdir, m_process_all_files, m_argparser,
            verbose, log_level):
        """
        Test main() function. Mock CustomArgumentParser to return values
        desired for test. Parametrize different combinations of verbosity
        and log level. Verify that logging configured properly for verbose
        setting.
        """
        m_exists.return_value = True
        m_isdir.return_value = True

        # Mock up the proper return values.
        m_parse_args = MagicMock(
            src_directory="/abc",
            dst_directory="/def",
            simon_sez=True,
            verbose=verbose,
        )

        attrs = {
            'parse_args.return_value': m_parse_args,
        }

        # This one configured to return m_parse_args.
        m_parse_args_container = MagicMock()
        m_parse_args_container.configure_mock(**attrs)
        m_argparser.return_value = m_parse_args_container

        # Invoke the unit.
        retval = main()

        # Confirm expected behavior
        m_logging.basicConfig.called_once_with(level=log_level)
        m_process_all_files.assert_called_with('/abc', '/def', simon_sez=True)
开发者ID:eigenholser,项目名称:jpeg_rename,代码行数:37,代码来源:test_copy_metadata_main.py

示例10: test_override_endpoint

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_override_endpoint(self):
     """check that a session catalog is overriden"""
     mock = MagicMock()
     config = {'auth.get_access.return_value': self.access}
     mock.configure_mock(**config)
     self.osclients._session_v3 = mock
     self.override_endpoint()
     self.assertOverrideEndpoint()
开发者ID:Fiware,项目名称:ops.Skuld,代码行数:10,代码来源:test_osclients.py

示例11: test_is_element_displayed_splinter

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_is_element_displayed_splinter(self, page, splinter, splinter_strategy):
     root_element = MagicMock()
     root_element.configure_mock(
         **{"find_by_{0}.return_value.first.visible".format(splinter_strategy): True}
     )
     locator = (splinter_strategy, str(random.random()))
     region = Region(page, root=root_element)
     assert region.is_element_displayed(*locator)
开发者ID:davehunt,项目名称:PyPOM,代码行数:10,代码来源:test_region.py

示例12: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def setUp(self):
     fake_cluster_monitor = MagicMock()
     attributes = {'name': 'I am a fake',
                   'fsid': 12345,
                   'get_sync_object.return_value': fake_cluster_monitor,
                   'osds_by_id': {0: {'up': True}, 1: {'up': False}}}
     fake_cluster_monitor.configure_mock(**attributes)
     self.osd_map = OsdMap(1, None)
     self.factory = OsdRequestFactory(fake_cluster_monitor)
开发者ID:abonas,项目名称:calamari,代码行数:11,代码来源:test_osd_request_factory.py

示例13: test_fail_execute_cmd_and_check_result

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_fail_execute_cmd_and_check_result(self, mock_popen):
     process_mock = MagicMock()
     attrs = {'wait.return_value': None, 'returncode': 1}
     process_mock.configure_mock(**attrs)
     mock_popen.return_value = process_mock
     creator = deb.DebianPackageCreator("", "", "")
     creator.workspace_path = "/tmp/eventlog_workspace10_31_55/eventlog"
     with pytest.raises(Exception):
         creator._execute_cmd_and_check_result(["a", "b", "c"])
开发者ID:jgrycz,项目名称:study,代码行数:11,代码来源:test_debian_package.py

示例14: test_pass_execute_cmd_and_check_result

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
 def test_pass_execute_cmd_and_check_result(self, mock_subproc_popen):
     process_mock = MagicMock()
     attrs = {'wait.return_value': None, 'returncode': 0}
     process_mock.configure_mock(**attrs)
     mock_subproc_popen.return_value = process_mock
     creator = deb.DebianPackageCreator("", "", "")
     creator.workspace_path = "/tmp/eventlog_workspace10_31_55"
     creator._execute_cmd_and_check_result(["a", "b", "c"])
     assert mock_subproc_popen.called is True
开发者ID:jgrycz,项目名称:study,代码行数:11,代码来源:test_debian_package.py

示例15: test_repr

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import configure_mock [as 别名]
    def test_repr(self):
        relation = Relation(id=1, resolwe=MagicMock())
        relation.type = 'compare'
        relation.unit = 'min'
        relation.category = 'background'

        # `name` cannot be mocked in another way
        sample_1 = MagicMock()
        sample_1.configure_mock(name='sample_1')
        sample_2 = MagicMock()
        sample_2.configure_mock(name='sample_2')
        relation._samples = [sample_1, sample_2]

        # Positions and labels are given
        relation.partitions = [
            {'id': 3, 'entity': 1, 'position': 10, 'label': 'first'},
            {'id': 4, 'entity': 2, 'position': 20, 'label': 'second'},
        ]
        self.assertEqual(
            str(relation),
            "Relation id: 1, type: 'compare', category: 'background', "
            "samples: {first (10 min): sample_1, second (20 min): sample_2}"
        )

        # Only labels are given
        relation.partitions = [
            {'id': 3, 'entity': 1, 'position': None, 'label': 'first'},
            {'id': 4, 'entity': 2, 'position': None, 'label': 'second'},
        ]
        self.assertEqual(
            str(relation),
            "Relation id: 1, type: 'compare', category: 'background', "
            "samples: {first: sample_1, second: sample_2}"
        )

        # Only positions are given
        relation.partitions = [
            {'id': 3, 'entity': 1, 'position': 10, 'label': None},
            {'id': 4, 'entity': 2, 'position': 20, 'label': None},
        ]
        self.assertEqual(
            str(relation),
            "Relation id: 1, type: 'compare', category: 'background', "
            "samples: {10 min: sample_1, 20 min: sample_2}"
        )

        # Only sample names are given
        relation.partitions = [
            {'id': 3, 'entity': 1, 'position': None, 'label': None},
            {'id': 4, 'entity': 2, 'position': None, 'label': None},
        ]
        self.assertEqual(
            str(relation),
            "Relation id: 1, type: 'compare', category: 'background', "
            "samples: {sample_1, sample_2}"
        )
开发者ID:JureZmrzlikar,项目名称:resolwe-bio-py,代码行数:58,代码来源:test_relations.py


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