Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit fda43e0

Browse files
fix: Test failures due to grpcio changes
* Failures can be found in googleapis/python-api-common-protos#223
1 parent ff229a5 commit fda43e0

2 files changed

Lines changed: 50 additions & 16 deletions

File tree

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,31 @@ def test_init_w_api_endpoint(creds):
133133
client_options = {"api_endpoint": "testendpoint.google.com"}
134134
client = publisher.Client(client_options=client_options, credentials=creds)
135135

136-
assert (client._transport.grpc_channel._channel.target()).decode(
137-
"utf-8"
138-
) == "testendpoint.google.com:443"
136+
# Behavior to include dns prefix changed in gRPCv1.63
137+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
138+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
139+
assert (client._transport.grpc_channel._channel.target()).decode(
140+
"utf-8"
141+
) == "dns:///testendpoint.google.com:443"
142+
else:
143+
assert (client._transport.grpc_channel._channel.target()).decode(
144+
"utf-8"
145+
) == "testendpoint.google.com:443"
139146

140147

141148
def test_init_w_empty_client_options(creds):
142149
client = publisher.Client(client_options={}, credentials=creds)
143-
144-
assert (client._transport.grpc_channel._channel.target()).decode(
145-
"utf-8"
146-
) == publisher_client.PublisherClient.SERVICE_ADDRESS
150+
151+
# Behavior to include dns prefix changed in gRPCv1.63
152+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
153+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
154+
assert (client._transport.grpc_channel._channel.target()).decode(
155+
"utf-8"
156+
) == "dns:///pubsub.googleapis.com:443"
157+
else:
158+
assert (client._transport.grpc_channel._channel.target()).decode(
159+
"utf-8"
160+
) == "pubsub.googleapis.com:443"
147161

148162

149163
def test_init_client_options_pass_through():
@@ -182,7 +196,7 @@ def test_init_emulator(monkeypatch):
182196
# Sadly, there seems to be no good way to do this without poking at
183197
# the private API of gRPC.
184198
channel = client._transport.publish._channel
185-
assert channel.target().decode("utf8") == "/foo/bar:123"
199+
assert channel.target().decode("utf8") == "dns:////foo/bar:123"
186200

187201

188202
def test_message_ordering_enabled(creds):

tests/unit/pubsub_v1/subscriber/test_subscriber_client.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,32 @@ def test_init_w_api_endpoint(creds):
6666
client_options = {"api_endpoint": "testendpoint.google.com"}
6767
client = subscriber.Client(client_options=client_options, credentials=creds)
6868

69-
assert (client._transport.grpc_channel._channel.target()).decode(
70-
"utf-8"
71-
) == "testendpoint.google.com:443"
69+
# Behavior to include dns prefix changed in gRPCv1.63
70+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
71+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
72+
assert (client._transport.grpc_channel._channel.target()).decode(
73+
"utf-8"
74+
) == "dns:///testendpoint.google.com:443"
75+
else:
76+
assert (client._transport.grpc_channel._channel.target()).decode(
77+
"utf-8"
78+
) == "testendpoint.google.com:443"
7279

7380

7481
def test_init_w_empty_client_options(creds):
7582
client = subscriber.Client(client_options={}, credentials=creds)
76-
77-
assert (client._transport.grpc_channel._channel.target()).decode(
78-
"utf-8"
79-
) == subscriber_client.SubscriberClient.SERVICE_ADDRESS
83+
84+
85+
# Behavior to include dns prefix changed in gRPCv1.63
86+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
87+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
88+
assert (client._transport.grpc_channel._channel.target()).decode(
89+
"utf-8"
90+
) == "dns:///pubsub.googleapis.com:443"
91+
else:
92+
assert (client._transport.grpc_channel._channel.target()).decode(
93+
"utf-8"
94+
) == "pubsub.googleapis.com:443"
8095

8196

8297
def test_init_client_options_pass_through():
@@ -115,7 +130,12 @@ def test_init_emulator(monkeypatch):
115130
# Sadly, there seems to be no good way to do this without poking at
116131
# the private API of gRPC.
117132
channel = client._transport.pull._channel
118-
assert channel.target().decode("utf8") == "/baz/bacon:123"
133+
# Behavior to include dns prefix changed in gRPCv1.63
134+
grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]]
135+
if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63):
136+
assert channel.target().decode("utf8") == "dns:////baz/bacon:123"
137+
else:
138+
assert channel.target().decode("utf8") == "baz/bacon:123"
119139

120140

121141
def test_class_method_factory():

0 commit comments

Comments
 (0)