Skip to content

Commit

Permalink
Trace: pick up fixes to GAPIC generator. (#6577)
Browse files Browse the repository at this point in the history
Includes fixes from these PRs:

- googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389)
- googleapis/gapic-generator#2396 (for #5523 and dupes).

Includes changes to generated tests.

Removes now-spurious docstring fixups.

Closes #6511.
  • Loading branch information
tseaver authored Nov 19, 2018
1 parent d489f4f commit 8a70f6b
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=trace_service_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -113,13 +113,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = trace_service_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -95,6 +97,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def patch_traces(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=trace_service_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -133,13 +133,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = trace_service_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -94,6 +96,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def batch_write_spans(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
8 changes: 1 addition & 7 deletions packages/google-cloud-trace/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)

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

# Fix up imports
s.replace(
Expand All @@ -43,10 +44,3 @@
'google/**/proto/*_pb2.py',
r"(^.*$\n)*",
r"# -*- coding: utf-8 -*-\n\g<0>")

# GAPIC-Generator is mangling some docstrings
# Missing blank line after bulleted list
s.replace(
"google/cloud/trace_v1/gapic/trace_service_client.py",
' ::\n\n',
'')
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud import trace_v1
Expand Down Expand Up @@ -62,7 +65,10 @@ class CustomException(Exception):
class TestTraceServiceClient(object):
def test_patch_traces(self):
channel = ChannelStub()
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

# Setup Request
project_id = 'projectId-1969970175'
Expand All @@ -79,7 +85,10 @@ def test_patch_traces(self):
def test_patch_traces_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

# Setup Request
project_id = 'projectId-1969970175'
Expand All @@ -118,7 +130,10 @@ def test_get_trace(self):
def test_get_trace_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

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

def test_list_traces_exception(self):
channel = ChannelStub(responses=[CustomException()])
client = trace_v1.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v1.TraceServiceClient()

# Setup request
project_id = 'projectId-1969970175'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud import trace_v2
Expand Down Expand Up @@ -64,7 +67,10 @@ class CustomException(Exception):
class TestTraceServiceClient(object):
def test_batch_write_spans(self):
channel = ChannelStub()
client = trace_v2.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v2.TraceServiceClient()

# Setup Request
name = client.project_path('[PROJECT]')
Expand All @@ -81,7 +87,10 @@ def test_batch_write_spans(self):
def test_batch_write_spans_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = trace_v2.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v2.TraceServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = trace_v2.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v2.TraceServiceClient()

# Setup Request
name = client.span_path('[PROJECT]', '[TRACE]', '[SPAN]')
Expand All @@ -130,7 +142,10 @@ def test_create_span(self):
def test_create_span_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = trace_v2.TraceServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = trace_v2.TraceServiceClient()

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

0 comments on commit 8a70f6b

Please sign in to comment.