當前位置: 首頁>>代碼示例>>Python>>正文


Python CloudVisionHook.create_reference_image方法代碼示例

本文整理匯總了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.create_reference_image方法的典型用法代碼示例。如果您正苦於以下問題:Python CloudVisionHook.create_reference_image方法的具體用法?Python CloudVisionHook.create_reference_image怎麽用?Python CloudVisionHook.create_reference_image使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook的用法示例。


在下文中一共展示了CloudVisionHook.create_reference_image方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: execute

# 需要導入模塊: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 別名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import create_reference_image [as 別名]
 def execute(self, context):
     try:
         hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
         return hook.create_reference_image(
             location=self.location,
             product_id=self.product_id,
             reference_image=self.reference_image,
             reference_image_id=self.reference_image_id,
             project_id=self.project_id,
             retry=self.retry,
             timeout=self.timeout,
             metadata=self.metadata,
         )
     except AlreadyExists:
         self.log.info(
             "ReferenceImage with id %s already exists. Exiting from the create operation.",
             self.product_id,
         )
         return self.reference_image_id
開發者ID:astronomerio,項目名稱:incubator-airflow,代碼行數:21,代碼來源: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 create_reference_image [as 別名]

#.........這裏部分代碼省略.........
                timeout=None,
                metadata=None,
            )
        err = cm.exception
        # self.assertIn("The required parameter 'project_id' is missing", str(err))
        self.assertTrue(err)
        self.assertIn(
            "The ProductSet name provided in the object ({}) is different than the name "
            "created from the input parameters ({}). Please either: 1) Remove the ProductSet "
            "name, 2) Remove the location and productset_id parameters, 3) Unify the "
            "ProductSet name and input parameters.".format(explicit_ps_name, template_ps_name),
            str(err),
        )
        update_product_set_method.assert_not_called()

    @mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
    def test_delete_productset(self, get_conn):
        # Given
        delete_product_set_method = get_conn.return_value.delete_product_set
        delete_product_set_method.return_value = None
        name = ProductSearchClient.product_set_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCTSET_ID_TEST)
        # When
        response = self.hook.delete_product_set(
            location=LOC_ID_TEST, product_set_id=PRODUCTSET_ID_TEST, project_id=PROJECT_ID_TEST
        )
        # Then
        self.assertIsNone(response)
        delete_product_set_method.assert_called_once_with(name=name, retry=None, timeout=None, metadata=None)

    @mock.patch(
        'airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn',
        **{'return_value.create_reference_image.return_value': REFERENCE_IMAGE_TEST}
    )
    def test_create_reference_image_explicit_id(self, get_conn):
        # Given
        create_reference_image_method = get_conn.return_value.create_reference_image

        # When
        result = self.hook.create_reference_image(
            project_id=PROJECT_ID_TEST,
            location=LOC_ID_TEST,
            product_id=PRODUCT_ID_TEST,
            reference_image=REFERENCE_IMAGE_WITHOUT_ID_NAME,
            reference_image_id=REFERENCE_IMAGE_ID_TEST,
        )
        # Then
        # Product ID was provided explicitly in the method call above, should be returned from the method
        self.assertEqual(result, REFERENCE_IMAGE_ID_TEST)
        create_reference_image_method.assert_called_once_with(
            parent=PRODUCT_NAME,
            reference_image=REFERENCE_IMAGE_WITHOUT_ID_NAME,
            reference_image_id=REFERENCE_IMAGE_ID_TEST,
            retry=None,
            timeout=None,
            metadata=None,
        )

    @mock.patch(
        'airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn',
        **{'return_value.create_reference_image.return_value': REFERENCE_IMAGE_TEST}
    )
    def test_create_reference_image_autogenerated_id(self, get_conn):
        # Given
        create_reference_image_method = get_conn.return_value.create_reference_image

        # When
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:70,代碼來源:test_gcp_vision_hook.py


注:本文中的airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.create_reference_image方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。