Skip to content

Commit 7591229

Browse files
committed
Making all modules in gcloud package pylint compliant.
1 parent c80cf50 commit 7591229

File tree

5 files changed

+62
-37
lines changed

5 files changed

+62
-37
lines changed

gcloud/connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Module to define base Connection class used by all APIs."""
2+
13
import httplib2
24

35

@@ -18,15 +20,16 @@ class Connection(object):
1820
"""A pointer to represent an empty value for default arguments."""
1921

2022
def __init__(self, credentials=None):
21-
""":type credentials: :class:`gcloud.credentials.Credentials`
23+
"""
24+
:type credentials: :class:`gcloud.credentials.Credentials`
2225
:param credentials: The OAuth2 Credentials to use for this connection.
23-
2426
"""
2527

2628
self._credentials = credentials
2729

2830
@property
2931
def credentials(self):
32+
"""Get the connection's credentials."""
3033
return self._credentials
3134

3235
@property
@@ -37,7 +40,9 @@ def http(self):
3740
:returns: A Http object used to transport data.
3841
"""
3942
if not hasattr(self, '_http'):
43+
# pylint: disable=attribute-defined-outside-init
4044
self._http = httplib2.Http()
4145
if self._credentials:
4246
self._http = self._credentials.authorize(self._http)
47+
# pylint: enable=attribute-defined-outside-init
4348
return self._http

gcloud/credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from oauth2client import client
44

55

6-
class Credentials(object):
6+
class Credentials(object): # pylint: disable=too-few-public-methods
77
"""An object used to simplify the OAuth2 credentials library.
88
99
.. note::

gcloud/demo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This is demo code, globally disable docstrings.
2+
# pylint: disable=missing-docstring
13
from code import interact
24
import itertools
35
import os.path
@@ -34,7 +36,7 @@ def run(self):
3436

3537
interact('(Hit CTRL-D to exit...)', local=self.LOCALS)
3638

37-
def wait(self):
39+
def wait(self): # pylint: disable=no-self-use
3840
raw_input()
3941

4042
@classmethod
@@ -106,4 +108,6 @@ def _execute_lines(self, lines):
106108
self.wait()
107109

108110
# Yes, this is crazy unsafe... but it's demo code.
111+
# pylint: disable=exec-used
109112
exec('\n'.join(lines), self.GLOBALS, self.LOCALS)
113+
# pylint: enable=exec-used

gcloud/test_connection.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
# This is test code, globally disable docstrings.
2+
# pylint: disable=missing-docstring
13
import unittest2
24

35

4-
class TestConnection(unittest2.TestCase):
6+
class TestConnection(unittest2.TestCase): # pylint: disable=R0904
57

6-
def _getTargetClass(self):
8+
def _getTargetClass(self): # pylint: disable=invalid-name,no-self-use
79
from gcloud.connection import Connection
810
return Connection
911

10-
def _makeOne(self, *args, **kw):
12+
def _makeOne(self, *args, **kw): # pylint: disable=invalid-name
1113
return self._getTargetClass()(*args, **kw)
1214

1315
def test_ctor_defaults(self):
@@ -21,7 +23,7 @@ def test_ctor_explicit(self):
2123

2224
def test_http_w_existing(self):
2325
conn = self._makeOne()
24-
conn._http = http = object()
26+
conn._http = http = object() # pylint: disable=protected-access
2527
self.assertTrue(conn.http is http)
2628

2729
def test_http_wo_creds(self):
@@ -34,12 +36,15 @@ def test_http_w_creds(self):
3436

3537
authorized = object()
3638

37-
class Creds(object):
38-
39+
class Creds(object): # pylint: disable=too-few-public-methods
3940
def authorize(self, http):
41+
# pylint: disable=attribute-defined-outside-init
4042
self._called_with = http
43+
# pylint: enable=attribute-defined-outside-init
4144
return authorized
4245
creds = Creds()
4346
conn = self._makeOne(creds)
4447
self.assertTrue(conn.http is authorized)
48+
# pylint: disable=protected-access
4549
self.assertTrue(isinstance(creds._called_with, Http))
50+
# pylint: enable=protected-access

gcloud/test_credentials.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,75 @@
1+
# This is test code, globally disable docstrings.
2+
# pylint: disable=missing-docstring
13
import unittest2
24

35

4-
class TestCredentials(unittest2.TestCase):
6+
class TestCredentials(unittest2.TestCase): # pylint: disable=R0904
57

6-
def _getTargetClass(self):
8+
def _getTargetClass(self): # pylint: disable=invalid-name,no-self-use
79
from gcloud.credentials import Credentials
810
return Credentials
911

10-
def test_get_for_service_account_wo_scope(self):
12+
def test_get_for_service_account_wo_scope(self): # pylint: disable=C0103
1113
from tempfile import NamedTemporaryFile
1214
from gcloud import credentials
15+
# pylint: disable=invalid-name
1316
CLIENT_EMAIL = 'phred@example.com'
1417
PRIVATE_KEY = 'SEEkR1t'
18+
# pylint: enable=invalid-name
1519
cls = self._getTargetClass()
1620
client = _Client()
1721
with _Monkey(credentials, client=client):
18-
with NamedTemporaryFile() as f:
19-
f.write(PRIVATE_KEY)
20-
f.flush()
21-
found = cls.get_for_service_account(CLIENT_EMAIL, f.name)
22+
with NamedTemporaryFile() as file_obj:
23+
file_obj.write(PRIVATE_KEY)
24+
file_obj.flush()
25+
found = cls.get_for_service_account(CLIENT_EMAIL,
26+
file_obj.name)
27+
# pylint: disable=protected-access
2228
self.assertTrue(found is client._signed)
23-
self.assertEqual(client._called_with,
24-
{'service_account_name': CLIENT_EMAIL,
25-
'private_key': PRIVATE_KEY,
26-
'scope': None,
27-
})
29+
expected_called_with = {'service_account_name': CLIENT_EMAIL,
30+
'private_key': PRIVATE_KEY,
31+
'scope': None}
32+
self.assertEqual(client._called_with, expected_called_with)
33+
# pylint: enable=protected-access
2834

29-
def test_get_for_service_account_w_scope(self):
35+
def test_get_for_service_account_w_scope(self): # pylint: disable=C0103
3036
from tempfile import NamedTemporaryFile
3137
from gcloud import credentials
38+
# pylint: disable=invalid-name
3239
CLIENT_EMAIL = 'phred@example.com'
3340
PRIVATE_KEY = 'SEEkR1t'
3441
SCOPE = 'SCOPE'
42+
# pylint: enable=invalid-name
3543
cls = self._getTargetClass()
3644
client = _Client()
3745
with _Monkey(credentials, client=client):
38-
with NamedTemporaryFile() as f:
39-
f.write(PRIVATE_KEY)
40-
f.flush()
41-
found = cls.get_for_service_account(CLIENT_EMAIL, f.name,
42-
SCOPE)
46+
with NamedTemporaryFile() as file_obj:
47+
file_obj.write(PRIVATE_KEY)
48+
file_obj.flush()
49+
found = cls.get_for_service_account(CLIENT_EMAIL,
50+
file_obj.name, SCOPE)
51+
# pylint: disable=protected-access
4352
self.assertTrue(found is client._signed)
44-
self.assertEqual(client._called_with,
45-
{'service_account_name': CLIENT_EMAIL,
46-
'private_key': PRIVATE_KEY,
47-
'scope': SCOPE,
48-
})
53+
expected_called_with = {'service_account_name': CLIENT_EMAIL,
54+
'private_key': PRIVATE_KEY,
55+
'scope': SCOPE}
56+
self.assertEqual(client._called_with, expected_called_with)
57+
# pylint: enable=protected-access
4958

5059

51-
class _Client(object):
52-
60+
class _Client(object): # pylint: disable=too-few-public-methods
5361
def __init__(self):
5462
self._signed = object()
5563

56-
def SignedJwtAssertionCredentials(self, **kw):
64+
def SignedJwtAssertionCredentials(self, **kw): # pylint: disable=C0103
65+
# pylint: disable=attribute-defined-outside-init
5766
self._called_with = kw
67+
# pylint: enable=attribute-defined-outside-init
5868
return self._signed
5969

6070

61-
class _Monkey(object):
71+
class _Monkey(object): # pylint: disable=too-few-public-methods
72+
6273
# context-manager for replacing module names in the scope of a test.
6374

6475
def __init__(self, module, **kw):

0 commit comments

Comments
 (0)