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


Python exceptions.InvalidArgument方法代碼示例

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


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

示例1: test_cannot_use_foreign_key

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def test_cannot_use_foreign_key(client, cleanup):
    document_id = "cannot" + UNIQUE_RESOURCE_ID
    document = client.document("foreign-key", document_id)
    # Add to clean-up before API request (in case ``create()`` fails).
    cleanup(document.delete)

    other_client = firestore.Client(
        project="other-prahj", credentials=client._credentials, database="dee-bee"
    )
    assert other_client._database_string != client._database_string
    fake_doc = other_client.document("foo", "bar")
    with pytest.raises(InvalidArgument):
        document.create({"ref": fake_doc}) 
開發者ID:googleapis,項目名稱:python-firestore,代碼行數:15,代碼來源:test_system.py

示例2: test_delete_note

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def test_delete_note(self):
        samples.delete_note(self.note_id, PROJECT_ID)
        try:
            samples.get_note(self.note_obj, PROJECT_ID)
        except InvalidArgument:
            pass
        else:
            # didn't raise exception we expected
            assert (False) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:11,代碼來源:samples_test.py

示例3: test_batch_get_assets_history

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def test_batch_get_assets_history(asset_bucket, capsys):
    bucket_asset_name = '//storage.googleapis.com/{}'.format(BUCKET)
    asset_names = [bucket_asset_name, ]

    @backoff.on_exception(
        backoff.expo, (AssertionError, InvalidArgument), max_time=30
    )
    def eventually_consistent_test():
        quickstart_batchgetassetshistory.batch_get_assets_history(
            PROJECT, asset_names)
        out, _ = capsys.readouterr()

        assert bucket_asset_name in out

    eventually_consistent_test() 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:17,代碼來源:quickstart_batchgetassetshistory_test.py

示例4: test_unary_error

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def test_unary_error(echo):
    message = 'Bad things! Bad things!'
    with pytest.raises(exceptions.InvalidArgument) as exc:
        echo.echo({
            'error': {
                'code': code_pb2.Code.Value('INVALID_ARGUMENT'),
                'message': message,
            },
        })
        assert exc.value.code == 400
        assert exc.value.message == message 
開發者ID:googleapis,項目名稱:gapic-generator-python,代碼行數:13,代碼來源:test_grpc_unary.py

示例5: test_async_unary_error

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def test_async_unary_error(async_echo):
    message = 'Bad things! Bad things!'
    with pytest.raises(exceptions.InvalidArgument) as exc:
        await async_echo.echo({
            'error': {
                'code': code_pb2.Code.Value('INVALID_ARGUMENT'),
                'message': message,
            },
        })
        assert exc.value.code == 400
        assert exc.value.message == message 
開發者ID:googleapis,項目名稱:gapic-generator-python,代碼行數:13,代碼來源:test_grpc_unary.py

示例6: _listen_print_loop

# 需要導入模塊: from google.api_core import exceptions [as 別名]
# 或者: from google.api_core.exceptions import InvalidArgument [as 別名]
def _listen_print_loop(self, responses):
        """Iterates through server responses and prints them.
        The responses passed is a generator that will block until a response
        is provided by the server.
        Each response may contain multiple results, and each result may contain
        multiple alternatives; for details, see https://goo.gl/tjCPAU.  Here we
        print only the transcription for the top alternative of the top result.
        """
        try:
            for response in responses:
                # If not a valid response, move on to next potential one
                if not response.results:
                    continue

                # The `results` list is consecutive. For streaming, we only care about
                # the first result being considered, since once it's `is_final`, it
                # moves on to considering the next utterance.
                result = response.results[0]
                if not result.alternatives:
                    continue

                # Display the transcription of the top alternative.
                transcript = result.alternatives[0].transcript

                # Parse the final utterance
                if result.is_final:
                    rospy.logdebug("Google Speech result: {}".format(transcript))
                    # Received data is Unicode, convert it to string
                    transcript = transcript.encode('utf-8')
                    # Strip the initial space if any
                    if transcript.startswith(' '):
                        transcript = transcript[1:]
                    # Exit if needed
                    if transcript.lower() == 'exit' or rospy.is_shutdown():
                        self.shutdown()
                    # Send the rest of the sentence to topic
                    self.text_pub.publish(result[1])

        except InvalidArgument as e:
            rospy.logwarn("{} caught in Mic. Client".format(e))
            self.gspeech_client()
        except OutOfRange as e:
            rospy.logwarn("{} caught in Mic. Client".format(e))
            self.gspeech_client() 
開發者ID:piraka9011,項目名稱:dialogflow_ros,代碼行數:46,代碼來源:google_client.py


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