本文整理汇总了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})
示例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)
示例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
示例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
示例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()