Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Oct 9, 2024
1 parent acb97ca commit 7f9a7b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 1 addition & 3 deletions google/api_core/protobuf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def from_any_pb(pb_type, any_pb):
# Unpack the Any object and populate the protobuf message instance.
if not any_pb.Unpack(msg_pb):
raise TypeError(
"Could not convert\n Any[{}] to\n {}".format(
any_pb.TypeName(), msg_pb.DESCRIPTOR.full_name
)
f"Could not convert Any[{any_pb.TypeName()}] to {msg_pb.DESCRIPTOR.full_name}"
)

# Done; return the message.
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_protobuf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import pytest
import re

from google.api import http_pb2
from google.api_core import protobuf_helpers
Expand Down Expand Up @@ -65,7 +66,12 @@ def test_from_any_pb_failure():
in_message = any_pb2.Any()
in_message.Pack(date_pb2.Date(year=1990))

with pytest.raises(TypeError):
with pytest.raises(
TypeError,
match=re.escape(
"Could not convert Any[google.type.Date] to google.type.TimeOfDay"
),
):
protobuf_helpers.from_any_pb(timeofday_pb2.TimeOfDay, in_message)


Expand Down

0 comments on commit 7f9a7b9

Please sign in to comment.