diff --git a/gcloud/connection.py b/gcloud/connection.py index 7ecf47763ce04..f4ab29c8003e8 100644 --- a/gcloud/connection.py +++ b/gcloud/connection.py @@ -1,3 +1,5 @@ +"""Module to define base Connection class used by all APIs.""" + import httplib2 @@ -18,15 +20,16 @@ class Connection(object): """A pointer to represent an empty value for default arguments.""" def __init__(self, credentials=None): - """:type credentials: :class:`gcloud.credentials.Credentials` + """ + :type credentials: :class:`gcloud.credentials.Credentials` :param credentials: The OAuth2 Credentials to use for this connection. - """ self._credentials = credentials @property def credentials(self): + """Get the connection's credentials.""" return self._credentials @property @@ -37,7 +40,9 @@ def http(self): :returns: A Http object used to transport data. """ if not hasattr(self, '_http'): + # pylint: disable=attribute-defined-outside-init self._http = httplib2.Http() if self._credentials: self._http = self._credentials.authorize(self._http) + # pylint: enable=attribute-defined-outside-init return self._http diff --git a/gcloud/credentials.py b/gcloud/credentials.py index e4bcb7d32fe08..ab2c22141175c 100644 --- a/gcloud/credentials.py +++ b/gcloud/credentials.py @@ -3,7 +3,7 @@ from oauth2client import client -class Credentials(object): +class Credentials(object): # pylint: disable=too-few-public-methods """An object used to simplify the OAuth2 credentials library. .. note:: diff --git a/gcloud/demo.py b/gcloud/demo.py index 28aa4108c69ba..c4f6e0f94580f 100644 --- a/gcloud/demo.py +++ b/gcloud/demo.py @@ -1,3 +1,5 @@ +# This is demo code, globally disable docstrings. +# pylint: disable=missing-docstring from code import interact import itertools import os.path @@ -34,7 +36,7 @@ def run(self): interact('(Hit CTRL-D to exit...)', local=self.LOCALS) - def wait(self): + def wait(self): # pylint: disable=no-self-use raw_input() @classmethod @@ -106,4 +108,6 @@ def _execute_lines(self, lines): self.wait() # Yes, this is crazy unsafe... but it's demo code. + # pylint: disable=exec-used exec('\n'.join(lines), self.GLOBALS, self.LOCALS) + # pylint: enable=exec-used diff --git a/gcloud/test_connection.py b/gcloud/test_connection.py index 1e0ebb8f690fd..ed51b1bb3560c 100644 --- a/gcloud/test_connection.py +++ b/gcloud/test_connection.py @@ -1,13 +1,15 @@ +# This is test code, globally disable docstrings. +# pylint: disable=missing-docstring import unittest2 -class TestConnection(unittest2.TestCase): +class TestConnection(unittest2.TestCase): # pylint: disable=R0904 - def _getTargetClass(self): + def _getTargetClass(self): # pylint: disable=invalid-name,no-self-use from gcloud.connection import Connection return Connection - def _makeOne(self, *args, **kw): + def _makeOne(self, *args, **kw): # pylint: disable=invalid-name return self._getTargetClass()(*args, **kw) def test_ctor_defaults(self): @@ -21,7 +23,7 @@ def test_ctor_explicit(self): def test_http_w_existing(self): conn = self._makeOne() - conn._http = http = object() + conn._http = http = object() # pylint: disable=protected-access self.assertTrue(conn.http is http) def test_http_wo_creds(self): @@ -34,12 +36,15 @@ def test_http_w_creds(self): authorized = object() - class Creds(object): - + class Creds(object): # pylint: disable=too-few-public-methods def authorize(self, http): + # pylint: disable=attribute-defined-outside-init self._called_with = http + # pylint: enable=attribute-defined-outside-init return authorized creds = Creds() conn = self._makeOne(creds) self.assertTrue(conn.http is authorized) + # pylint: disable=protected-access self.assertTrue(isinstance(creds._called_with, Http)) + # pylint: enable=protected-access diff --git a/gcloud/test_credentials.py b/gcloud/test_credentials.py index 69a06ec4ef0de..7daa95cce3c41 100644 --- a/gcloud/test_credentials.py +++ b/gcloud/test_credentials.py @@ -1,64 +1,75 @@ +# This is test code, globally disable docstrings. +# pylint: disable=missing-docstring import unittest2 -class TestCredentials(unittest2.TestCase): +class TestCredentials(unittest2.TestCase): # pylint: disable=R0904 - def _getTargetClass(self): + def _getTargetClass(self): # pylint: disable=invalid-name,no-self-use from gcloud.credentials import Credentials return Credentials - def test_get_for_service_account_wo_scope(self): + def test_get_for_service_account_wo_scope(self): # pylint: disable=C0103 from tempfile import NamedTemporaryFile from gcloud import credentials + # pylint: disable=invalid-name CLIENT_EMAIL = 'phred@example.com' PRIVATE_KEY = 'SEEkR1t' + # pylint: enable=invalid-name cls = self._getTargetClass() client = _Client() with _Monkey(credentials, client=client): - with NamedTemporaryFile() as f: - f.write(PRIVATE_KEY) - f.flush() - found = cls.get_for_service_account(CLIENT_EMAIL, f.name) + with NamedTemporaryFile() as file_obj: + file_obj.write(PRIVATE_KEY) + file_obj.flush() + found = cls.get_for_service_account(CLIENT_EMAIL, + file_obj.name) + # pylint: disable=protected-access self.assertTrue(found is client._signed) - self.assertEqual(client._called_with, - {'service_account_name': CLIENT_EMAIL, - 'private_key': PRIVATE_KEY, - 'scope': None, - }) + expected_called_with = {'service_account_name': CLIENT_EMAIL, + 'private_key': PRIVATE_KEY, + 'scope': None} + self.assertEqual(client._called_with, expected_called_with) + # pylint: enable=protected-access - def test_get_for_service_account_w_scope(self): + def test_get_for_service_account_w_scope(self): # pylint: disable=C0103 from tempfile import NamedTemporaryFile from gcloud import credentials + # pylint: disable=invalid-name CLIENT_EMAIL = 'phred@example.com' PRIVATE_KEY = 'SEEkR1t' SCOPE = 'SCOPE' + # pylint: enable=invalid-name cls = self._getTargetClass() client = _Client() with _Monkey(credentials, client=client): - with NamedTemporaryFile() as f: - f.write(PRIVATE_KEY) - f.flush() - found = cls.get_for_service_account(CLIENT_EMAIL, f.name, - SCOPE) + with NamedTemporaryFile() as file_obj: + file_obj.write(PRIVATE_KEY) + file_obj.flush() + found = cls.get_for_service_account(CLIENT_EMAIL, + file_obj.name, SCOPE) + # pylint: disable=protected-access self.assertTrue(found is client._signed) - self.assertEqual(client._called_with, - {'service_account_name': CLIENT_EMAIL, - 'private_key': PRIVATE_KEY, - 'scope': SCOPE, - }) + expected_called_with = {'service_account_name': CLIENT_EMAIL, + 'private_key': PRIVATE_KEY, + 'scope': SCOPE} + self.assertEqual(client._called_with, expected_called_with) + # pylint: enable=protected-access -class _Client(object): - +class _Client(object): # pylint: disable=too-few-public-methods def __init__(self): self._signed = object() - def SignedJwtAssertionCredentials(self, **kw): + def SignedJwtAssertionCredentials(self, **kw): # pylint: disable=C0103 + # pylint: disable=attribute-defined-outside-init self._called_with = kw + # pylint: enable=attribute-defined-outside-init return self._signed -class _Monkey(object): +class _Monkey(object): # pylint: disable=too-few-public-methods + # context-manager for replacing module names in the scope of a test. def __init__(self, module, **kw):