Skip to content

Commit 88b6ecc

Browse files
authored
Error reporting: pick up fixes to GAPIC generator. (googleapis#6522)
Closes googleapis#6496. Includes generated test changes. Includes fixes from these PRs: - googleapis/gapic-generator#2407 - googleapis/gapic-generator#2396
1 parent d97ef0c commit 88b6ecc

11 files changed

+130
-39
lines changed

error_reporting/google/cloud/errorreporting_v1beta1/gapic/error_group_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self,
8181
transport=None,
8282
channel=None,
8383
credentials=None,
84-
client_config=error_group_service_client_config.config,
84+
client_config=None,
8585
client_info=None):
8686
"""Constructor.
8787
@@ -114,13 +114,20 @@ def __init__(self,
114114
your own client library.
115115
"""
116116
# Raise deprecation warnings for things we want to go away.
117-
if client_config:
118-
warnings.warn('The `client_config` argument is deprecated.',
119-
PendingDeprecationWarning)
117+
if client_config is not None:
118+
warnings.warn(
119+
'The `client_config` argument is deprecated.',
120+
PendingDeprecationWarning,
121+
stacklevel=2)
122+
else:
123+
client_config = error_group_service_client_config.config
124+
120125
if channel:
121126
warnings.warn(
122127
'The `channel` argument is deprecated; use '
123-
'`transport` instead.', PendingDeprecationWarning)
128+
'`transport` instead.',
129+
PendingDeprecationWarning,
130+
stacklevel=2)
124131

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

error_reporting/google/cloud/errorreporting_v1beta1/gapic/error_stats_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self,
8989
transport=None,
9090
channel=None,
9191
credentials=None,
92-
client_config=error_stats_service_client_config.config,
92+
client_config=None,
9393
client_info=None):
9494
"""Constructor.
9595
@@ -122,13 +122,20 @@ def __init__(self,
122122
your own client library.
123123
"""
124124
# Raise deprecation warnings for things we want to go away.
125-
if client_config:
126-
warnings.warn('The `client_config` argument is deprecated.',
127-
PendingDeprecationWarning)
125+
if client_config is not None:
126+
warnings.warn(
127+
'The `client_config` argument is deprecated.',
128+
PendingDeprecationWarning,
129+
stacklevel=2)
130+
else:
131+
client_config = error_stats_service_client_config.config
132+
128133
if channel:
129134
warnings.warn(
130135
'The `channel` argument is deprecated; use '
131-
'`transport` instead.', PendingDeprecationWarning)
136+
'`transport` instead.',
137+
PendingDeprecationWarning,
138+
stacklevel=2)
132139

133140
# Instantiate the transport.
134141
# The transport is responsible for handling serialization and

error_reporting/google/cloud/errorreporting_v1beta1/gapic/report_errors_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(self,
8686
transport=None,
8787
channel=None,
8888
credentials=None,
89-
client_config=report_errors_service_client_config.config,
89+
client_config=None,
9090
client_info=None):
9191
"""Constructor.
9292
@@ -119,13 +119,20 @@ def __init__(self,
119119
your own client library.
120120
"""
121121
# Raise deprecation warnings for things we want to go away.
122-
if client_config:
123-
warnings.warn('The `client_config` argument is deprecated.',
124-
PendingDeprecationWarning)
122+
if client_config is not None:
123+
warnings.warn(
124+
'The `client_config` argument is deprecated.',
125+
PendingDeprecationWarning,
126+
stacklevel=2)
127+
else:
128+
client_config = report_errors_service_client_config.config
129+
125130
if channel:
126131
warnings.warn(
127132
'The `channel` argument is deprecated; use '
128-
'`transport` instead.', PendingDeprecationWarning)
133+
'`transport` instead.',
134+
PendingDeprecationWarning,
135+
stacklevel=2)
129136

130137
# Instantiate the transport.
131138
# The transport is responsible for handling serialization and

error_reporting/google/cloud/errorreporting_v1beta1/gapic/transports/error_group_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self,
6262
credentials=credentials,
6363
)
6464

65+
self._channel = channel
66+
6567
# gRPC uses objects called "stubs" that are bound to the
6668
# channel and provide a basic method for each RPC.
6769
self._stubs = {
@@ -92,6 +94,15 @@ def create_channel(cls,
9294
scopes=cls._OAUTH_SCOPES,
9395
)
9496

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

error_reporting/google/cloud/errorreporting_v1beta1/gapic/transports/error_stats_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self,
6262
credentials=credentials,
6363
)
6464

65+
self._channel = channel
66+
6567
# gRPC uses objects called "stubs" that are bound to the
6668
# channel and provide a basic method for each RPC.
6769
self._stubs = {
@@ -92,6 +94,15 @@ def create_channel(cls,
9294
scopes=cls._OAUTH_SCOPES,
9395
)
9496

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

error_reporting/google/cloud/errorreporting_v1beta1/gapic/transports/report_errors_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self,
6262
credentials=credentials,
6363
)
6464

65+
self._channel = channel
66+
6567
# gRPC uses objects called "stubs" that are bound to the
6668
# channel and provide a basic method for each RPC.
6769
self._stubs = {
@@ -92,6 +94,15 @@ def create_channel(cls,
9294
scopes=cls._OAUTH_SCOPES,
9395
)
9496

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

error_reporting/synth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
s.move(library / 'google/cloud/errorreporting_v1beta1/proto')
3333
s.move(library / 'google/cloud/errorreporting_v1beta1/gapic')
34+
s.move(library / 'tests/unit/gapic/v1beta1')
35+
s.move(library / 'tests/system/gapic/v1beta1')
3436

3537
# Fix up imports
3638
s.replace(

error_reporting/tests/system/gapic/v1beta1/test_system_report_errors_service_v1beta1.py

Lines changed: 2 additions & 0 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");

error_reporting/tests/unit/gapic/v1beta1/test_error_group_service_client_v1beta1.py

Lines changed: 19 additions & 8 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 errorreporting_v1beta1
@@ -69,8 +72,10 @@ def test_get_group(self):
6972

7073
# Mock the API response
7174
channel = ChannelStub(responses=[expected_response])
72-
client = errorreporting_v1beta1.ErrorGroupServiceClient(
73-
channel=channel)
75+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
76+
with patch as create_channel:
77+
create_channel.return_value = channel
78+
client = errorreporting_v1beta1.ErrorGroupServiceClient()
7479

7580
# Setup Request
7681
group_name = client.group_path('[PROJECT]', '[GROUP]')
@@ -87,8 +92,10 @@ def test_get_group(self):
8792
def test_get_group_exception(self):
8893
# Mock the API response
8994
channel = ChannelStub(responses=[CustomException()])
90-
client = errorreporting_v1beta1.ErrorGroupServiceClient(
91-
channel=channel)
95+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
96+
with patch as create_channel:
97+
create_channel.return_value = channel
98+
client = errorreporting_v1beta1.ErrorGroupServiceClient()
9299

93100
# Setup request
94101
group_name = client.group_path('[PROJECT]', '[GROUP]')
@@ -105,8 +112,10 @@ def test_update_group(self):
105112

106113
# Mock the API response
107114
channel = ChannelStub(responses=[expected_response])
108-
client = errorreporting_v1beta1.ErrorGroupServiceClient(
109-
channel=channel)
115+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
116+
with patch as create_channel:
117+
create_channel.return_value = channel
118+
client = errorreporting_v1beta1.ErrorGroupServiceClient()
110119

111120
# Setup Request
112121
group = {}
@@ -123,8 +132,10 @@ def test_update_group(self):
123132
def test_update_group_exception(self):
124133
# Mock the API response
125134
channel = ChannelStub(responses=[CustomException()])
126-
client = errorreporting_v1beta1.ErrorGroupServiceClient(
127-
channel=channel)
135+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
136+
with patch as create_channel:
137+
create_channel.return_value = channel
138+
client = errorreporting_v1beta1.ErrorGroupServiceClient()
128139

129140
# Setup request
130141
group = {}

error_reporting/tests/unit/gapic/v1beta1/test_error_stats_service_client_v1beta1.py

Lines changed: 27 additions & 12 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 errorreporting_v1beta1
@@ -74,8 +77,10 @@ def test_list_group_stats(self):
7477

7578
# Mock the API response
7679
channel = ChannelStub(responses=[expected_response])
77-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
78-
channel=channel)
80+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
81+
with patch as create_channel:
82+
create_channel.return_value = channel
83+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
7984

8085
# Setup Request
8186
project_name = client.project_path('[PROJECT]')
@@ -95,8 +100,10 @@ def test_list_group_stats(self):
95100

96101
def test_list_group_stats_exception(self):
97102
channel = ChannelStub(responses=[CustomException()])
98-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
99-
channel=channel)
103+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
104+
with patch as create_channel:
105+
create_channel.return_value = channel
106+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
100107

101108
# Setup request
102109
project_name = client.project_path('[PROJECT]')
@@ -120,8 +127,10 @@ def test_list_events(self):
120127

121128
# Mock the API response
122129
channel = ChannelStub(responses=[expected_response])
123-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
124-
channel=channel)
130+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
131+
with patch as create_channel:
132+
create_channel.return_value = channel
133+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
125134

126135
# Setup Request
127136
project_name = client.project_path('[PROJECT]')
@@ -141,8 +150,10 @@ def test_list_events(self):
141150

142151
def test_list_events_exception(self):
143152
channel = ChannelStub(responses=[CustomException()])
144-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
145-
channel=channel)
153+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
154+
with patch as create_channel:
155+
create_channel.return_value = channel
156+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
146157

147158
# Setup request
148159
project_name = client.project_path('[PROJECT]')
@@ -160,8 +171,10 @@ def test_delete_events(self):
160171

161172
# Mock the API response
162173
channel = ChannelStub(responses=[expected_response])
163-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
164-
channel=channel)
174+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
175+
with patch as create_channel:
176+
create_channel.return_value = channel
177+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
165178

166179
# Setup Request
167180
project_name = client.project_path('[PROJECT]')
@@ -178,8 +191,10 @@ def test_delete_events(self):
178191
def test_delete_events_exception(self):
179192
# Mock the API response
180193
channel = ChannelStub(responses=[CustomException()])
181-
client = errorreporting_v1beta1.ErrorStatsServiceClient(
182-
channel=channel)
194+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
195+
with patch as create_channel:
196+
create_channel.return_value = channel
197+
client = errorreporting_v1beta1.ErrorStatsServiceClient()
183198

184199
# Setup request
185200
project_name = client.project_path('[PROJECT]')

0 commit comments

Comments
 (0)