From aa10306754539afb73296153d3b6a8af6c2f8662 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Fri, 23 Feb 2018 16:34:37 -0800 Subject: [PATCH] Re-enable lint for tests, remove usage of pylint (#4921) --- packages/google-cloud-trace/.flake8 | 12 +++++++++ packages/google-cloud-trace/nox.py | 9 ++++--- .../tests/unit/v1/test__gax_v1.py | 26 ++++++++++++------- .../tests/unit/v1/test_client_v1.py | 9 ++++--- .../tests/unit/v2/test__gax_v2.py | 7 +++-- 5 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 packages/google-cloud-trace/.flake8 diff --git a/packages/google-cloud-trace/.flake8 b/packages/google-cloud-trace/.flake8 new file mode 100644 index 000000000000..1f44a90f8195 --- /dev/null +++ b/packages/google-cloud-trace/.flake8 @@ -0,0 +1,12 @@ +[flake8] +exclude = + # Exclude generated code. + **/proto/** + **/gapic/** + *_pb2.py + + # Standard linting exemptions. + __pycache__, + .git, + *.pyc, + conf.py diff --git a/packages/google-cloud-trace/nox.py b/packages/google-cloud-trace/nox.py index 04b30f0a5408..638342d97654 100644 --- a/packages/google-cloud-trace/nox.py +++ b/packages/google-cloud-trace/nox.py @@ -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 diff --git a/packages/google-cloud-trace/tests/unit/v1/test__gax_v1.py b/packages/google-cloud-trace/tests/unit/v1/test__gax_v1.py index 6d6667bb855b..4815517f0d4e 100644 --- a/packages/google-cloud-trace/tests/unit/v1/test__gax_v1.py +++ b/packages/google-cloud-trace/tests/unit/v1/test__gax_v1.py @@ -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) @@ -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) @@ -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 @@ -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, @@ -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, '') @@ -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']) @@ -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: diff --git a/packages/google-cloud-trace/tests/unit/v1/test_client_v1.py b/packages/google-cloud-trace/tests/unit/v1/test_client_v1.py index a5fb8e62bccb..494e03d75b8d 100644 --- a/packages/google-cloud-trace/tests/unit/v1/test_client_v1.py +++ b/packages/google-cloud-trace/tests/unit/v1/test_client_v1.py @@ -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) @@ -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( @@ -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, diff --git a/packages/google-cloud-trace/tests/unit/v2/test__gax_v2.py b/packages/google-cloud-trace/tests/unit/v2/test__gax_v2.py index 5766f6232493..92b3b866ba06 100644 --- a/packages/google-cloud-trace/tests/unit/v2/test__gax_v2.py +++ b/packages/google-cloud-trace/tests/unit/v2/test__gax_v2.py @@ -83,7 +83,7 @@ class _Base(object): 'build_id': _str_to_truncatablestr( st_build_id), - }, + }, 'source_version': _str_to_truncatablestr( st_source_version), @@ -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 = { @@ -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']) @@ -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: