Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace: pick up fixes to GAPIC generator. #6577

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions trace/google/cloud/trace_v1/gapic/trace_service_client.py
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
17 changes: 12 additions & 5 deletions trace/google/cloud/trace_v2/gapic/trace_service_client.py
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 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',
'')
33 changes: 27 additions & 6 deletions trace/tests/unit/gapic/v1/test_trace_service_client_v1.py
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
23 changes: 19 additions & 4 deletions trace/tests/unit/gapic/v2/test_trace_service_client_v2.py
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