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


Python CloudVisionHook.safe_search_detection方法代码示例

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


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

示例1: execute

# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import safe_search_detection [as 别名]
 def execute(self, context):
     hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
     return hook.safe_search_detection(
         image=self.image,
         max_results=self.max_results,
         retry=self.retry,
         timeout=self.timeout,
         additional_properties=self.additional_properties,
     )
开发者ID:astronomerio,项目名称:incubator-airflow,代码行数:11,代码来源:gcp_vision_operator.py

示例2: TestGcpVisionHook

# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import safe_search_detection [as 别名]

#.........这里部分代码省略.........
        self.hook.label_detection(image=DETECT_TEST_IMAGE)

        # Then
        label_detection_method.assert_called_once_with(
            image=DETECT_TEST_IMAGE, max_results=None, retry=None, timeout=None
        )

    @mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
    def test_label_detection_with_additional_properties(self, annotator_client_mock):
        # Given
        label_detection_method = annotator_client_mock.label_detection
        label_detection_method.return_value = AnnotateImageResponse(
            label_annotations=[EntityAnnotation(description="test", score=0.5)]
        )

        # When
        self.hook.label_detection(
            image=DETECT_TEST_IMAGE, additional_properties={"prop1": "test1", "prop2": "test2"}
        )

        # Then
        label_detection_method.assert_called_once_with(
            image=DETECT_TEST_IMAGE, max_results=None, retry=None, timeout=None, prop1="test1", prop2="test2"
        )

    @mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
    def test_label_detection_with_error_response(self, annotator_client_mock):
        # Given
        detect_text_method = annotator_client_mock.label_detection
        detect_text_method.return_value = AnnotateImageResponse(
            error={"code": 3, "message": "test error message"}
        )

        # When
        with self.assertRaises(AirflowException) as msg:
            self.hook.label_detection(image=DETECT_TEST_IMAGE)

        err = msg.exception
        self.assertIn("test error message", str(err))

    @mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
    def test_safe_search_detection(self, annotator_client_mock):
        # Given
        safe_search_detection_method = annotator_client_mock.safe_search_detection
        safe_search_detection_method.return_value = AnnotateImageResponse(
            safe_search_annotation=SafeSearchAnnotation(
                adult="VERY_UNLIKELY",
                spoof="VERY_UNLIKELY",
                medical="VERY_UNLIKELY",
                violence="VERY_UNLIKELY",
                racy="VERY_UNLIKELY",
            )
        )

        # When
        self.hook.safe_search_detection(image=DETECT_TEST_IMAGE)

        # Then
        safe_search_detection_method.assert_called_once_with(
            image=DETECT_TEST_IMAGE, max_results=None, retry=None, timeout=None
        )

    @mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
    def test_safe_search_detection_with_additional_properties(self, annotator_client_mock):
        # Given
        safe_search_detection_method = annotator_client_mock.safe_search_detection
        safe_search_detection_method.return_value = AnnotateImageResponse(
            safe_search_annotation=SafeSearchAnnotation(
                adult="VERY_UNLIKELY",
                spoof="VERY_UNLIKELY",
                medical="VERY_UNLIKELY",
                violence="VERY_UNLIKELY",
                racy="VERY_UNLIKELY",
            )
        )

        # When
        self.hook.safe_search_detection(
            image=DETECT_TEST_IMAGE, additional_properties={"prop1": "test1", "prop2": "test2"}
        )

        # Then
        safe_search_detection_method.assert_called_once_with(
            image=DETECT_TEST_IMAGE, max_results=None, retry=None, timeout=None, prop1="test1", prop2="test2"
        )

    @mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
    def test_safe_search_detection_with_error_response(self, annotator_client_mock):
        # Given
        detect_text_method = annotator_client_mock.safe_search_detection
        detect_text_method.return_value = AnnotateImageResponse(
            error={"code": 3, "message": "test error message"}
        )

        # When
        with self.assertRaises(AirflowException) as msg:
            self.hook.safe_search_detection(image=DETECT_TEST_IMAGE)

        err = msg.exception
        self.assertIn("test error message", str(err))
开发者ID:apache,项目名称:incubator-airflow,代码行数:104,代码来源:test_gcp_vision_hook.py


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