Skip to content

Commit b8cf418

Browse files
authored
Trace: pick up fixes to GAPIC generator. (googleapis#6577)
Includes fixes from these PRs: - googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389) - googleapis/gapic-generator#2396 (for googleapis#5523 and dupes). Includes changes to generated tests. Removes now-spurious docstring fixups. Closes googleapis#6511.
1 parent a7ce1ff commit b8cf418

7 files changed

Lines changed: 93 additions & 27 deletions

File tree

trace/google/cloud/trace_v1/gapic/trace_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self,
8080
transport=None,
8181
channel=None,
8282
credentials=None,
83-
client_config=trace_service_client_config.config,
83+
client_config=None,
8484
client_info=None):
8585
"""Constructor.
8686
@@ -113,13 +113,20 @@ def __init__(self,
113113
your own client library.
114114
"""
115115
# Raise deprecation warnings for things we want to go away.
116-
if client_config:
117-
warnings.warn('The `client_config` argument is deprecated.',
118-
PendingDeprecationWarning)
116+
if client_config is not None:
117+
warnings.warn(
118+
'The `client_config` argument is deprecated.',
119+
PendingDeprecationWarning,
120+
stacklevel=2)
121+
else:
122+
client_config = trace_service_client_config.config
123+
119124
if channel:
120125
warnings.warn(
121126
'The `channel` argument is deprecated; use '
122-
'`transport` instead.', PendingDeprecationWarning)
127+
'`transport` instead.',
128+
PendingDeprecationWarning,
129+
stacklevel=2)
123130

124131
# Instantiate the transport.
125132
# The transport is responsible for handling serialization and

trace/google/cloud/trace_v1/gapic/transports/trace_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self,
6666
credentials=credentials,
6767
)
6868

69+
self._channel = channel
70+
6971
# gRPC uses objects called "stubs" that are bound to the
7072
# channel and provide a basic method for each RPC.
7173
self._stubs = {
@@ -95,6 +97,15 @@ def create_channel(cls,
9597
scopes=cls._OAUTH_SCOPES,
9698
)
9799

100+
@property
101+
def channel(self):
102+
"""The gRPC channel used by the transport.
103+
104+
Returns:
105+
grpc.Channel: A gRPC channel object.
106+
"""
107+
return self._channel
108+
98109
@property
99110
def patch_traces(self):
100111
"""Return the gRPC stub for {$apiMethod.name}.

trace/google/cloud/trace_v2/gapic/trace_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self,
100100
transport=None,
101101
channel=None,
102102
credentials=None,
103-
client_config=trace_service_client_config.config,
103+
client_config=None,
104104
client_info=None):
105105
"""Constructor.
106106
@@ -133,13 +133,20 @@ def __init__(self,
133133
your own client library.
134134
"""
135135
# Raise deprecation warnings for things we want to go away.
136-
if client_config:
137-
warnings.warn('The `client_config` argument is deprecated.',
138-
PendingDeprecationWarning)
136+
if client_config is not None:
137+
warnings.warn(
138+
'The `client_config` argument is deprecated.',
139+
PendingDeprecationWarning,
140+
stacklevel=2)
141+
else:
142+
client_config = trace_service_client_config.config
143+
139144
if channel:
140145
warnings.warn(
141146
'The `channel` argument is deprecated; use '
142-
'`transport` instead.', PendingDeprecationWarning)
147+
'`transport` instead.',
148+
PendingDeprecationWarning,
149+
stacklevel=2)
143150

144151
# Instantiate the transport.
145152
# The transport is responsible for handling serialization and

trace/google/cloud/trace_v2/gapic/transports/trace_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def __init__(self,
6565
credentials=credentials,
6666
)
6767

68+
self._channel = channel
69+
6870
# gRPC uses objects called "stubs" that are bound to the
6971
# channel and provide a basic method for each RPC.
7072
self._stubs = {
@@ -94,6 +96,15 @@ def create_channel(cls,
9496
scopes=cls._OAUTH_SCOPES,
9597
)
9698

99+
@property
100+
def channel(self):
101+
"""The gRPC channel used by the transport.
102+
103+
Returns:
104+
grpc.Channel: A gRPC channel object.
105+
"""
106+
return self._channel
107+
97108
@property
98109
def batch_write_spans(self):
99110
"""Return the gRPC stub for {$apiMethod.name}.

trace/synth.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929

3030
s.move(library / f'google/cloud/trace_{version}')
31+
s.move(library / f'tests/unit/gapic/{version}')
3132

3233
# Fix up imports
3334
s.replace(
@@ -43,10 +44,3 @@
4344
'google/**/proto/*_pb2.py',
4445
r"(^.*$\n)*",
4546
r"# -*- coding: utf-8 -*-\n\g<0>")
46-
47-
# GAPIC-Generator is mangling some docstrings
48-
# Missing blank line after bulleted list
49-
s.replace(
50-
"google/cloud/trace_v1/gapic/trace_service_client.py",
51-
' ::\n\n',
52-
'')

trace/tests/unit/gapic/v1/test_trace_service_client_v1.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +15,7 @@
1315
# limitations under the License.
1416
"""Unit tests."""
1517

18+
import mock
1619
import pytest
1720

1821
from google.cloud import trace_v1
@@ -62,7 +65,10 @@ class CustomException(Exception):
6265
class TestTraceServiceClient(object):
6366
def test_patch_traces(self):
6467
channel = ChannelStub()
65-
client = trace_v1.TraceServiceClient(channel=channel)
68+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
69+
with patch as create_channel:
70+
create_channel.return_value = channel
71+
client = trace_v1.TraceServiceClient()
6672

6773
# Setup Request
6874
project_id = 'projectId-1969970175'
@@ -79,7 +85,10 @@ def test_patch_traces(self):
7985
def test_patch_traces_exception(self):
8086
# Mock the API response
8187
channel = ChannelStub(responses=[CustomException()])
82-
client = trace_v1.TraceServiceClient(channel=channel)
88+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
89+
with patch as create_channel:
90+
create_channel.return_value = channel
91+
client = trace_v1.TraceServiceClient()
8392

8493
# Setup request
8594
project_id = 'projectId-1969970175'
@@ -100,7 +109,10 @@ def test_get_trace(self):
100109

101110
# Mock the API response
102111
channel = ChannelStub(responses=[expected_response])
103-
client = trace_v1.TraceServiceClient(channel=channel)
112+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
113+
with patch as create_channel:
114+
create_channel.return_value = channel
115+
client = trace_v1.TraceServiceClient()
104116

105117
# Setup Request
106118
project_id = 'projectId-1969970175'
@@ -118,7 +130,10 @@ def test_get_trace(self):
118130
def test_get_trace_exception(self):
119131
# Mock the API response
120132
channel = ChannelStub(responses=[CustomException()])
121-
client = trace_v1.TraceServiceClient(channel=channel)
133+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
134+
with patch as create_channel:
135+
create_channel.return_value = channel
136+
client = trace_v1.TraceServiceClient()
122137

123138
# Setup request
124139
project_id = 'projectId-1969970175'
@@ -140,7 +155,10 @@ def test_list_traces(self):
140155

141156
# Mock the API response
142157
channel = ChannelStub(responses=[expected_response])
143-
client = trace_v1.TraceServiceClient(channel=channel)
158+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
159+
with patch as create_channel:
160+
create_channel.return_value = channel
161+
client = trace_v1.TraceServiceClient()
144162

145163
# Setup Request
146164
project_id = 'projectId-1969970175'
@@ -158,7 +176,10 @@ def test_list_traces(self):
158176

159177
def test_list_traces_exception(self):
160178
channel = ChannelStub(responses=[CustomException()])
161-
client = trace_v1.TraceServiceClient(channel=channel)
179+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
180+
with patch as create_channel:
181+
create_channel.return_value = channel
182+
client = trace_v1.TraceServiceClient()
162183

163184
# Setup request
164185
project_id = 'projectId-1969970175'

trace/tests/unit/gapic/v2/test_trace_service_client_v2.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +15,7 @@
1315
# limitations under the License.
1416
"""Unit tests."""
1517

18+
import mock
1619
import pytest
1720

1821
from google.cloud import trace_v2
@@ -64,7 +67,10 @@ class CustomException(Exception):
6467
class TestTraceServiceClient(object):
6568
def test_batch_write_spans(self):
6669
channel = ChannelStub()
67-
client = trace_v2.TraceServiceClient(channel=channel)
70+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
71+
with patch as create_channel:
72+
create_channel.return_value = channel
73+
client = trace_v2.TraceServiceClient()
6874

6975
# Setup Request
7076
name = client.project_path('[PROJECT]')
@@ -81,7 +87,10 @@ def test_batch_write_spans(self):
8187
def test_batch_write_spans_exception(self):
8288
# Mock the API response
8389
channel = ChannelStub(responses=[CustomException()])
84-
client = trace_v2.TraceServiceClient(channel=channel)
90+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
91+
with patch as create_channel:
92+
create_channel.return_value = channel
93+
client = trace_v2.TraceServiceClient()
8594

8695
# Setup request
8796
name = client.project_path('[PROJECT]')
@@ -104,7 +113,10 @@ def test_create_span(self):
104113

105114
# Mock the API response
106115
channel = ChannelStub(responses=[expected_response])
107-
client = trace_v2.TraceServiceClient(channel=channel)
116+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
117+
with patch as create_channel:
118+
create_channel.return_value = channel
119+
client = trace_v2.TraceServiceClient()
108120

109121
# Setup Request
110122
name = client.span_path('[PROJECT]', '[TRACE]', '[SPAN]')
@@ -130,7 +142,10 @@ def test_create_span(self):
130142
def test_create_span_exception(self):
131143
# Mock the API response
132144
channel = ChannelStub(responses=[CustomException()])
133-
client = trace_v2.TraceServiceClient(channel=channel)
145+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
146+
with patch as create_channel:
147+
create_channel.return_value = channel
148+
client = trace_v2.TraceServiceClient()
134149

135150
# Setup request
136151
name = client.span_path('[PROJECT]', '[TRACE]', '[SPAN]')

0 commit comments

Comments
 (0)