Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Remove pending deprecation spew from unit tests. #2407

Merged
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
2 changes: 1 addition & 1 deletion showcase/python/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def unit(session, py):
session.virtualenv_dirname = 'unit-' + py

# Install all test dependencies, then install this package in-place.
session.install('pytest')
session.install('pytest', 'mock')
session.install('--pre', 'googleapis-common-protos')
session.install(
'-e',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ private List<ImportFileView> generateProtoImports(
}

private List<ImportFileView> generateTestStandardImports() {
return ImmutableList.of(createImport("pytest"));
ImmutableList.Builder<ImportFileView> imports = ImmutableList.builder();
imports.add(createImport("mock"));
imports.add(createImport("pytest"));
return imports.build();
}

private List<ImportFileView> generateSmokeTestStandardImports(boolean requireProjectId) {
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/com/google/api/codegen/py/main.snip
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
@end
@end
def __init__(self, transport=None, channel=None, credentials=None,
client_config={@api.clientConfigName}.config,
client_info=None):
client_config=None, client_info=None):
"""Constructor.

Args:
Expand Down Expand Up @@ -103,12 +102,16 @@
your own client library.
"""
@# Raise deprecation warnings for things we want to go away.
if client_config:
if client_config is not None:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
PendingDeprecationWarning, stacklevel=2)
else:
client_config = {@api.clientConfigName}.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
2 changes: 1 addition & 1 deletion src/main/resources/com/google/api/codegen/py/nox.py.snip
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
session.virtualenv_dirname = 'unit-' + py

@# Install all test dependencies, then install this package in-place.
session.install('pytest')
session.install('pytest', 'mock')
session.install('-e', '.')

@# Run py.test against the unit tests.
Expand Down
24 changes: 10 additions & 14 deletions src/main/resources/com/google/api/codegen/py/test.snip
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ class CustomException(Exception):

@# Mock the API response
channel = ChannelStub(responses = [iter([expected_response])])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@# Setup Request
{@initCode(test.initCode.lines)}
Expand Down Expand Up @@ -256,8 +255,7 @@ class CustomException(Exception):
def {@test.nameWithException}(self):
@# Mock the API response
channel = ChannelStub(responses = [CustomException()])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@if test.hasRequestParameters
@# Setup request
Expand All @@ -271,8 +269,7 @@ class CustomException(Exception):
@private pagedStreamingTestWithException(test, moduleName)
def {@test.nameWithException}(self):
channel = ChannelStub(responses = [CustomException()])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@if test.hasRequestParameters
@# Setup request
Expand All @@ -288,8 +285,7 @@ class CustomException(Exception):
def {@test.nameWithException}(self):
@# Mock the API response
channel = ChannelStub(responses = [CustomException()])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@if test.hasRequestParameters
@# Setup request
Expand All @@ -312,8 +308,7 @@ class CustomException(Exception):

@# Mock the API response
channel = ChannelStub(responses=[operation])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@if test.hasRequestParameters
@# Setup Request
Expand All @@ -336,8 +331,7 @@ class CustomException(Exception):

@# Mock the API response
channel = ChannelStub(responses=[operation])
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
{@clientSetup(test, moduleName)}

@if test.hasRequestParameters
@# Setup Request
Expand All @@ -350,8 +344,10 @@ class CustomException(Exception):
@end

@private clientSetup(test, moduleName)
client = {@moduleName}.{@test.serviceConstructorName}(
channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = {@moduleName}.{@test.serviceConstructorName}()
@end

@private responseInitCode(test)
Expand Down
Loading