Skip to content

Commit

Permalink
Re-enable lint for tests, remove usage of pylint (#4921)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Feb 24, 2018
1 parent 551da88 commit aa10306
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
12 changes: 12 additions & 0 deletions packages/google-cloud-trace/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
exclude =
# Exclude generated code.
**/proto/**
**/gapic/**
*_pb2.py

# Standard linting exemptions.
__pycache__,
.git,
*.pyc,
conf.py
9 changes: 5 additions & 4 deletions packages/google-cloud-trace/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def unit(session, py):

@nox.session
def lint(session):
"""Run flake8.
Returns a failure if flake8 finds linting errors or sufficiently
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.interpreter = 'python3.6'
session.install('flake8', *LOCAL_DEPS)
session.install('flake8')
session.install('.')
session.run('flake8', 'google/cloud/trace')
session.run('flake8', 'google', 'tests')


@nox.session
Expand Down
26 changes: 16 additions & 10 deletions packages/google-cloud-trace/tests/unit/v1/test__gax_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

from google.api_core import grpc_helpers


class _Base(object):
project = 'PROJECT'

def _make_one(self, gapic_client=None, handwritten_client=None):
from google.cloud.trace_v1.gapic import trace_service_client
from google.cloud.trace_v1.gapic import trace_service_client
channel = grpc_helpers.ChannelStub()
if gapic_client is None:
gapic_client = trace_service_client.TraceServiceClient(channel=channel)
gapic_client = trace_service_client.TraceServiceClient(
channel=channel)
if handwritten_client is None:
handwritten_client = mock.Mock()
api = self._get_target_class()(gapic_client, handwritten_client)
Expand All @@ -43,7 +45,7 @@ def _get_target_class():

def test_constructor(self):
from google.cloud.trace_v1.gapic import trace_service_client
channel = grpc_helpers.ChannelStub()
channel = grpc_helpers.ChannelStub()
gapic_client = trace_service_client.TraceServiceClient(channel=channel)
_, api = self._make_one(gapic_client, mock.sentinel.client)
self.assertIs(api._gapic_api, gapic_client)
Expand Down Expand Up @@ -165,7 +167,6 @@ def _make_trace_pb(
return trace_pb

def test_list_traces(self):
from google.api_core.page_iterator import GRPCIterator
from google.cloud._helpers import _rfc3339_to_datetime
from google.cloud._helpers import UTC
from google.cloud.trace_v1.gapic import trace_service_client
Expand Down Expand Up @@ -198,10 +199,11 @@ def test_list_traces(self):
labels)

gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient)
gapic_api.list_traces = mock.create_autospec(gapic_api.list_traces)
gapic_api.list_traces = mock.create_autospec(gapic_api.list_traces)
channel, api = self._make_one()

channel.ListTraces.response = trace_pb2.ListTracesResponse(traces=[trace_pb[0]])
channel.ListTraces.response = trace_pb2.ListTracesResponse(
traces=[trace_pb[0]])
iterator = api.list_traces(
project_id=self.project,
view=view_type,
Expand Down Expand Up @@ -238,8 +240,12 @@ def test_list_traces(self):
self.assertEqual(request.project_id, self.project)
self.assertEqual(request.view, view_type)
self.assertEqual(request.page_size, size)
self.assertEqual(request.start_time.ToDatetime(), datetime.datetime(1970, 1, 1, 0, 0))
self.assertEqual(request.end_time.ToDatetime(), datetime.datetime(1970, 1, 1, 0, 0))
self.assertEqual(
request.start_time.ToDatetime(),
datetime.datetime(1970, 1, 1, 0, 0))
self.assertEqual(
request.end_time.ToDatetime(),
datetime.datetime(1970, 1, 1, 0, 0))
self.assertEqual(request.filter, '')
self.assertEqual(request.order_by, '')

Expand Down Expand Up @@ -317,7 +323,6 @@ def _call_fut(self, client):

def test_it(self):
from google.cloud.trace.v1._gapic import _TraceAPI
from google.cloud._http import DEFAULT_USER_AGENT

credentials = object()
client = mock.Mock(_credentials=credentials, spec=['_credentials'])
Expand All @@ -332,7 +337,8 @@ def generated_api(**kwargs):
generated_api.SERVICE_ADDRESS = host

patch_api = mock.patch(
'google.cloud.trace.v1._gapic.trace_service_client.TraceServiceClient',
'google.cloud.trace.v1._gapic.trace_service_client.'
'TraceServiceClient',
new=generated_api)

with patch_api:
Expand Down
9 changes: 6 additions & 3 deletions packages/google-cloud-trace/tests/unit/v1/test_client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def test_patch_traces_default(self):

mock_trace_api = mock.Mock(spec=_TraceAPI)
mock_trace_api.patch_traces = mock.Mock()
patch = mock.patch('google.cloud.trace.v1.client.make_trace_api', return_value=mock_trace_api)
patch = mock.patch(
'google.cloud.trace.v1.client.make_trace_api',
return_value=mock_trace_api)

with patch:
client.patch_traces(traces=traces)
Expand All @@ -89,7 +91,9 @@ def test_patch_traces_explicit(self):

mock_trace_api = mock.Mock(spec=_TraceAPI)
mock_trace_api.patch_traces = mock.Mock()
patch = mock.patch('google.cloud.trace.v1.client.make_trace_api', return_value=mock_trace_api)
patch = mock.patch(
'google.cloud.trace.v1.client.make_trace_api',
return_value=mock_trace_api)

with patch:
client.patch_traces(
Expand Down Expand Up @@ -227,7 +231,6 @@ def list_traces(
order_by = 'traceId'
page_token = 'TOKEN'


with patch:
list_traces_called_with = client.list_traces(
project_id=self.project,
Expand Down
7 changes: 3 additions & 4 deletions packages/google-cloud-trace/tests/unit/v2/test__gax_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class _Base(object):
'build_id':
_str_to_truncatablestr(
st_build_id),
},
},
'source_version':
_str_to_truncatablestr(
st_source_version),
Expand Down Expand Up @@ -158,7 +158,6 @@ def test_constructor(self):

def test_batch_write_spans(self):
from google.cloud.trace_v2.gapic import trace_service_client
from google.cloud.trace_v2.proto.trace_pb2 import Span
from google.cloud.trace._gapic import _dict_mapping_to_pb

spans = {
Expand Down Expand Up @@ -296,7 +295,6 @@ def _call_fut(self, client):

def test_it(self):
from google.cloud.trace._gapic import _TraceAPI
from google.cloud._http import DEFAULT_USER_AGENT

credentials = object()
client = mock.Mock(_credentials=credentials, spec=['_credentials'])
Expand All @@ -311,7 +309,8 @@ def generated_api(**kwargs):
generated_api.SERVICE_ADDRESS = host

patch_api = mock.patch(
'google.cloud.trace._gapic.trace_service_client.TraceServiceClient',
'google.cloud.trace._gapic.trace_service_client.'
'TraceServiceClient',
new=generated_api)

with patch_api:
Expand Down

0 comments on commit aa10306

Please sign in to comment.