Skip to content

Commit 2032538

Browse files
author
Jon Wayne Parrott
authored
Re-enable lint for tests, remove usage of pylint (#4921)
1 parent e6bf6d3 commit 2032538

File tree

11 files changed

+58
-48
lines changed

11 files changed

+58
-48
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[flake8]
2+
exclude =
3+
# Exclude generated code.
4+
**/proto/**
5+
**/gapic/**
6+
*_pb2.py
7+
8+
# Standard linting exemptions.
9+
__pycache__,
10+
.git,
11+
*.pyc,
12+
conf.py

packages/google-cloud-firestore/google/cloud/firestore_v1beta1/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def _pre_commit(self, transaction, *args, **kwargs):
261261
self.retry_id = self.current_id
262262
try:
263263
return self.to_wrap(transaction, *args, **kwargs)
264-
except:
264+
except: # noqa
265265
# NOTE: If ``rollback`` fails this will lose the information
266266
# from the original failure.
267267
transaction._rollback()

packages/google-cloud-firestore/nox.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,15 @@ def system(session, py):
9999

100100
@nox.session
101101
def lint(session):
102-
"""Run flake8.
102+
"""Run linters.
103103
104-
Returns a failure if flake8 finds linting errors or sufficiently
104+
Returns a failure if the linters find linting errors or sufficiently
105105
serious code quality issues.
106106
"""
107107
session.interpreter = 'python3.6'
108-
session.install('flake8', 'pylint', 'gcp-devrel-py-tools', *LOCAL_DEPS)
108+
session.install('flake8')
109109
session.install('.')
110-
session.run('flake8', os.path.join('google', 'cloud', 'firestore'))
111-
session.run(
112-
'gcp-devrel-py-tools', 'run-pylint',
113-
'--config', 'pylint.config.py',
114-
'--library-filesets', 'google',
115-
'--test-filesets', 'tests',
116-
# Temporarily allow this to fail.
117-
success_codes=range(0, 100))
110+
session.run('flake8', 'google', 'tests')
118111

119112

120113
@nox.session

packages/google-cloud-firestore/tests/unit/test__helpers.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ def test_to_field_paths(self):
361361
klass = self._get_target_class()
362362

363363
update_values, field_paths = klass.to_field_paths(field_updates)
364-
self.assertEqual(update_values, {'a': {'b': field_updates[field_path]}})
364+
self.assertEqual(
365+
update_values, {'a': {'b': field_updates[field_path]}})
365366
self.assertEqual(field_paths, [field_path])
366367

367368

@@ -492,7 +493,8 @@ def test_geo_point(self):
492493
self.assertEqual(result, expected)
493494

494495
def test_array(self):
495-
from google.cloud.firestore_v1beta1.proto.document_pb2 import ArrayValue
496+
from google.cloud.firestore_v1beta1.proto.document_pb2 import (
497+
ArrayValue)
496498

497499
result = self._call_fut([
498500
99,
@@ -540,7 +542,8 @@ def _call_fut(values_dict):
540542
def test_many_types(self):
541543
from google.protobuf import struct_pb2
542544
from google.protobuf import timestamp_pb2
543-
from google.cloud.firestore_v1beta1.proto.document_pb2 import ArrayValue
545+
from google.cloud.firestore_v1beta1.proto.document_pb2 import (
546+
ArrayValue)
544547
from google.cloud.firestore_v1beta1.proto.document_pb2 import MapValue
545548

546549
dt_seconds = 1497397225
@@ -675,7 +678,7 @@ def test_float(self):
675678
value = _value_pb(double_value=float_val)
676679
self.assertEqual(self._call_fut(value), float_val)
677680

678-
@unittest.skipIf((3,) <= sys.version_info < (3,4,4),
681+
@unittest.skipIf((3,) <= sys.version_info < (3, 4, 4),
679682
'known datetime bug (bpo-23517) in Python')
680683
def test_datetime(self):
681684
from google.protobuf import timestamp_pb2
@@ -815,12 +818,13 @@ def _call_fut(value_fields, client=mock.sentinel.client):
815818

816819
return decode_dict(value_fields, client)
817820

818-
@unittest.skipIf((3,) <= sys.version_info < (3,4,4),
821+
@unittest.skipIf((3,) <= sys.version_info < (3, 4, 4),
819822
'known datetime bug (bpo-23517) in Python')
820823
def test_many_types(self):
821824
from google.protobuf import struct_pb2
822825
from google.protobuf import timestamp_pb2
823-
from google.cloud.firestore_v1beta1.proto.document_pb2 import ArrayValue
826+
from google.cloud.firestore_v1beta1.proto.document_pb2 import (
827+
ArrayValue)
824828
from google.cloud.firestore_v1beta1.proto.document_pb2 import MapValue
825829
from google.cloud._helpers import UTC
826830

@@ -1249,7 +1253,6 @@ def test_without_option(self):
12491253
self._helper(current_document=precondition)
12501254

12511255
def test_with_option(self):
1252-
from google.cloud.firestore_v1beta1.proto import common_pb2
12531256
from google.cloud.firestore_v1beta1.client import CreateIfMissingOption
12541257

12551258
option = CreateIfMissingOption(True)
@@ -1342,7 +1345,6 @@ def test_after_writes_not_allowed(self):
13421345
self._call_fut(transaction)
13431346

13441347
def test_after_writes_allowed(self):
1345-
from google.cloud.firestore_v1beta1._helpers import ReadAfterWriteError
13461348
from google.cloud.firestore_v1beta1.transaction import Transaction
13471349

13481350
transaction = Transaction(mock.sentinel.client)

packages/google-cloud-firestore/tests/unit/test_batch.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
import unittest
1616

17-
from google.gax.errors import GaxError
18-
from grpc import StatusCode
19-
from grpc._channel import _RPCState
2017
import mock
2118

2219

packages/google-cloud-firestore/tests/unit/test_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def test___call_options_property(self):
111111
self.assertIs(client._call_options, mock.sentinel.cached)
112112

113113
def test_collection_factory(self):
114-
from google.cloud.firestore_v1beta1.collection import CollectionReference
114+
from google.cloud.firestore_v1beta1.collection import (
115+
CollectionReference)
115116

116117
collection_id = 'users'
117118
client = self._make_default_one()
@@ -122,7 +123,8 @@ def test_collection_factory(self):
122123
self.assertIsInstance(collection, CollectionReference)
123124

124125
def test_collection_factory_nested(self):
125-
from google.cloud.firestore_v1beta1.collection import CollectionReference
126+
from google.cloud.firestore_v1beta1.collection import (
127+
CollectionReference)
126128

127129
client = self._make_default_one()
128130
parts = ('users', 'alovelace', 'beep')

packages/google-cloud-firestore/tests/unit/test_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class TestCollectionReference(unittest.TestCase):
2424

2525
@staticmethod
2626
def _get_target_class():
27-
from google.cloud.firestore_v1beta1.collection import CollectionReference
27+
from google.cloud.firestore_v1beta1.collection import (
28+
CollectionReference)
2829

2930
return CollectionReference
3031

packages/google-cloud-firestore/tests/unit/test_cross_language.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import functools
1516
import glob
1617
import json
1718
import os
1819
import unittest
1920

2021
import mock
21-
from google.cloud.firestore_v1beta1.proto import common_pb2
2222
from google.cloud.firestore_v1beta1.proto import test_pb2
2323
from google.protobuf import text_format
2424

25+
2526
class TestCrossLanguage(unittest.TestCase):
2627

2728
def test_cross_language(self):
@@ -34,9 +35,9 @@ def test_cross_language(self):
3435
test_proto.description,
3536
os.path.splitext(os.path.basename(test_filename))[0])
3637
if test_proto.WhichOneof("test") == "get":
37-
pass # The Get tests assume a call to GetDocument, but Python
38-
# calls BatchGetDocuments.
39-
# TODO: make this work.
38+
pass # The Get tests assume a call to GetDocument, but Python
39+
# calls BatchGetDocuments.
40+
# TODO: make this work.
4041
else:
4142
self.run_write_test(test_proto, desc)
4243

@@ -57,7 +58,7 @@ def run_write_test(self, test_proto, desc):
5758
tp = test_proto.create
5859
client, doc = self.setup(firestore_api, tp)
5960
data = convert_data(json.loads(tp.json_data))
60-
call = lambda: doc.create(data)
61+
call = functools.partial(doc.create, data)
6162
elif kind == "set":
6263
tp = test_proto.set
6364
client, doc = self.setup(firestore_api, tp)
@@ -71,7 +72,7 @@ def run_write_test(self, test_proto, desc):
7172
option = convert_precondition(tp.precondition)
7273
else:
7374
option = None
74-
call = lambda: doc.update(data, option)
75+
call = functools.partial(doc.update, data, option)
7576
elif kind == "update_paths":
7677
# Python client doesn't have a way to call update with
7778
# a list of field paths.
@@ -84,7 +85,7 @@ def run_write_test(self, test_proto, desc):
8485
option = convert_precondition(tp.precondition)
8586
else:
8687
option = None
87-
call = lambda: doc.delete(option)
88+
call = functools.partial(doc.delete, option)
8889

8990
if call is None:
9091
# TODO: remove this when we handle all kinds.
@@ -101,7 +102,6 @@ def run_write_test(self, test_proto, desc):
101102
transaction=None,
102103
options=client._call_options)
103104

104-
105105
def setup(self, firestore_api, proto):
106106
from google.cloud.firestore_v1beta1 import Client
107107
from google.cloud.firestore_v1beta1.client import DEFAULT_DATABASE
@@ -129,7 +129,7 @@ def convert_data(v):
129129
elif isinstance(v, list):
130130
return [convert_data(e) for e in v]
131131
elif isinstance(v, dict):
132-
return {k : convert_data(v2) for k, v2 in v.items()}
132+
return {k: convert_data(v2) for k, v2 in v.items()}
133133
else:
134134
return v
135135

packages/google-cloud-firestore/tests/unit/test_document.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def test_id_property(self):
164164
self.assertEqual(document.id, document_id)
165165

166166
def test_parent_property(self):
167-
from google.cloud.firestore_v1beta1.collection import CollectionReference
167+
from google.cloud.firestore_v1beta1.collection import (
168+
CollectionReference)
168169

169170
collection_id = 'grocery-store'
170171
document_id = 'market'
@@ -177,7 +178,8 @@ def test_parent_property(self):
177178
self.assertEqual(parent._path, (collection_id,))
178179

179180
def test_collection_factory(self):
180-
from google.cloud.firestore_v1beta1.collection import CollectionReference
181+
from google.cloud.firestore_v1beta1.collection import (
182+
CollectionReference)
181183

182184
collection_id = 'grocery-store'
183185
document_id = 'market'

packages/google-cloud-firestore/tests/unit/test_query.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ def test_where(self):
143143
self._compare_queries(query, new_query, '_field_filters')
144144

145145
def _where_unary_helper(self, value, op_enum, op_string='=='):
146-
from google.cloud.firestore_v1beta1.gapic import enums
147146
from google.cloud.firestore_v1beta1.proto import query_pb2
148147

149148
query = self._make_one_all_fields(skip_fields=('field_filters',))
@@ -653,6 +652,8 @@ def test__to_protobuf_limit_only(self):
653652
}
654653
expected_pb = query_pb2.StructuredQuery(**query_kwargs)
655654

655+
self.assertEqual(structured_query_pb, expected_pb)
656+
656657
def test_get_simple(self):
657658
# Create a minimal fake GAPIC.
658659
firestore_api = mock.Mock(spec=['run_query'])
@@ -1044,7 +1045,8 @@ class Test__query_response_to_snapshot(unittest.TestCase):
10441045

10451046
@staticmethod
10461047
def _call_fut(response_pb, collection, expected_prefix):
1047-
from google.cloud.firestore_v1beta1.query import _query_response_to_snapshot
1048+
from google.cloud.firestore_v1beta1.query import (
1049+
_query_response_to_snapshot)
10481050

10491051
return _query_response_to_snapshot(
10501052
response_pb, collection, expected_prefix)

0 commit comments

Comments
 (0)