本文整理汇总了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.text_detection方法的典型用法代码示例。如果您正苦于以下问题:Python CloudVisionHook.text_detection方法的具体用法?Python CloudVisionHook.text_detection怎么用?Python CloudVisionHook.text_detection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook
的用法示例。
在下文中一共展示了CloudVisionHook.text_detection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import text_detection [as 别名]
def execute(self, context):
hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
return hook.text_detection(
image=self.image,
max_results=self.max_results,
retry=self.retry,
timeout=self.timeout,
additional_properties=self.additional_properties,
)
示例2: TestGcpVisionHook
# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import text_detection [as 别名]
#.........这里部分代码省略.........
retry=None,
timeout=None,
metadata=None,
)
err = cm.exception
self.assertTrue(err)
self.assertIn(
"The Product name provided in the object ({}) is different than the name created from the input "
"parameters ({}). Please either: 1) Remove the Product name, 2) Remove the location and product_"
"id parameters, 3) Unify the Product name and input parameters.".format(
explicit_p_name, template_p_name
),
str(err),
)
update_product_method.assert_not_called()
@mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
def test_delete_product(self, get_conn):
# Given
delete_product_method = get_conn.return_value.delete_product
delete_product_method.return_value = None
name = ProductSearchClient.product_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCT_ID_TEST)
# When
response = self.hook.delete_product(
location=LOC_ID_TEST, product_id=PRODUCT_ID_TEST, project_id=PROJECT_ID_TEST
)
# Then
self.assertIsNone(response)
delete_product_method.assert_called_once_with(name=name, retry=None, timeout=None, metadata=None)
@mock.patch("airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.annotator_client")
def test_detect_text(self, annotator_client_mock):
# Given
detect_text_method = annotator_client_mock.text_detection
detect_text_method.return_value = AnnotateImageResponse(
text_annotations=[EntityAnnotation(description="test", score=0.5)]
)
# When
self.hook.text_detection(image=DETECT_TEST_IMAGE)
# Then
detect_text_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_detect_text_with_additional_properties(self, annotator_client_mock):
# Given
detect_text_method = annotator_client_mock.text_detection
detect_text_method.return_value = AnnotateImageResponse(
text_annotations=[EntityAnnotation(description="test", score=0.5)]
)
# When
self.hook.text_detection(
image=DETECT_TEST_IMAGE, additional_properties={"prop1": "test1", "prop2": "test2"}
)
# Then
detect_text_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_detect_text_with_error_response(self, annotator_client_mock):