summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Mueller <dirk@dmllr.de>2013-06-09 11:07:27 +0200
committerDirk Mueller <dirk@dmllr.de>2013-06-22 16:00:26 +0200
commit62579fbb217f4c1a4668e793ebaafaf668619206 (patch)
tree8a791ee5b60248ecc5f59b895c1e4049529ab918
parentd8a537c7fe9b1e455831d05d9ba0ab67e03fb3a5 (diff)
downloadpython-glanceclient-62579fbb217f4c1a4668e793ebaafaf668619206.tar.gz
Start using Pyflakes and Hacking
Instead of globally ignoring pyflakes and hacking warnings, only blacklist those that trigger very frequently so far, in order to clean them up in followup commits. Fix and start gating on the rest already. Change-Id: Ied7c7250061e3bf379e8286e8ce3b9e4af817faf
-rw-r--r--glanceclient/common/http.py5
-rw-r--r--glanceclient/exc.py24
-rw-r--r--glanceclient/openstack/common/importutils.py2
-rw-r--r--glanceclient/shell.py2
-rw-r--r--glanceclient/v1/__init__.py2
-rw-r--r--glanceclient/v1/client.py2
-rw-r--r--glanceclient/v1/image_members.py10
-rw-r--r--glanceclient/v2/image_members.py2
-rw-r--r--glanceclient/v2/shell.py2
-rwxr-xr-xrun_tests.sh4
-rw-r--r--tests/test_exc.py2
-rw-r--r--tests/test_http.py2
-rw-r--r--tests/test_shell.py2
-rw-r--r--tests/test_ssl.py12
-rw-r--r--tests/v1/test_shell.py8
-rw-r--r--tests/v2/test_members.py1
-rw-r--r--tox.ini6
17 files changed, 43 insertions, 45 deletions
diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py
index e609f8c..3379a18 100644
--- a/glanceclient/common/http.py
+++ b/glanceclient/common/http.py
@@ -145,8 +145,7 @@ class HTTPClient(object):
@staticmethod
def encode_headers(headers):
- """
- Encodes headers.
+ """Encodes headers.
Note: This should be used right before
sending anything out.
@@ -159,7 +158,7 @@ class HTTPClient(object):
return dict([(to_str(h), to_str(v)) for h, v in headers.iteritems()])
def _http_request(self, url, method, **kwargs):
- """ Send an http request with the specified characteristics.
+ """Send an http request with the specified characteristics.
Wrapper around httplib.HTTP(S)Connection.request to handle tasks such
as setting headers and error handling.
diff --git a/glanceclient/exc.py b/glanceclient/exc.py
index d5adb92..a8e2fef 100644
--- a/glanceclient/exc.py
+++ b/glanceclient/exc.py
@@ -26,7 +26,7 @@ class BaseException(Exception):
class CommandError(BaseException):
- """Invalid usage of CLI"""
+ """Invalid usage of CLI."""
class InvalidEndpoint(BaseException):
@@ -38,11 +38,11 @@ class CommunicationError(BaseException):
class ClientException(Exception):
- """DEPRECATED"""
+ """DEPRECATED!"""
class HTTPException(ClientException):
- """Base exception for all HTTP-derived exceptions"""
+ """Base exception for all HTTP-derived exceptions."""
code = 'N/A'
def __init__(self, details=None):
@@ -63,7 +63,7 @@ class HTTPMultipleChoices(HTTPException):
class BadRequest(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 400
@@ -72,7 +72,7 @@ class HTTPBadRequest(BadRequest):
class Unauthorized(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 401
@@ -81,7 +81,7 @@ class HTTPUnauthorized(Unauthorized):
class Forbidden(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 403
@@ -90,7 +90,7 @@ class HTTPForbidden(Forbidden):
class NotFound(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 404
@@ -103,7 +103,7 @@ class HTTPMethodNotAllowed(HTTPException):
class Conflict(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 409
@@ -112,7 +112,7 @@ class HTTPConflict(Conflict):
class OverLimit(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 413
@@ -133,7 +133,7 @@ class HTTPBadGateway(HTTPException):
class ServiceUnavailable(HTTPException):
- """DEPRECATED"""
+ """DEPRECATED!"""
code = 503
@@ -161,12 +161,12 @@ def from_response(response, body=None):
class NoTokenLookupException(Exception):
- """DEPRECATED"""
+ """DEPRECATED!"""
pass
class EndpointNotFound(Exception):
- """DEPRECATED"""
+ """DEPRECATED!"""
pass
diff --git a/glanceclient/openstack/common/importutils.py b/glanceclient/openstack/common/importutils.py
index 3bd277f..dbee325 100644
--- a/glanceclient/openstack/common/importutils.py
+++ b/glanceclient/openstack/common/importutils.py
@@ -24,7 +24,7 @@ import traceback
def import_class(import_str):
- """Returns a class from a string including module and class"""
+ """Returns a class from a string including module and class."""
mod_str, _sep, class_str = import_str.rpartition('.')
try:
__import__(mod_str)
diff --git a/glanceclient/shell.py b/glanceclient/shell.py
index 58f7686..aea3a7a 100644
--- a/glanceclient/shell.py
+++ b/glanceclient/shell.py
@@ -296,7 +296,7 @@ class OpenStackImagesShell(object):
# Compatibility check to remove API version as the trailing component
# in a service endpoint; also removes a trailing '/'
def _strip_version(self, endpoint):
- """Strip a version from the last component of an endpoint if present"""
+ """Strip version from the last component of endpoint if present."""
# Get rid of trailing '/' if present
if endpoint.endswith('/'):
diff --git a/glanceclient/v1/__init__.py b/glanceclient/v1/__init__.py
index b2db927..8982002 100644
--- a/glanceclient/v1/__init__.py
+++ b/glanceclient/v1/__init__.py
@@ -13,4 +13,4 @@
# License for the specific language governing permissions and limitations
# under the License.
-from glanceclient.v1.client import Client
+from glanceclient.v1.client import Client # noqa
diff --git a/glanceclient/v1/client.py b/glanceclient/v1/client.py
index 0f5980e..4d0fd27 100644
--- a/glanceclient/v1/client.py
+++ b/glanceclient/v1/client.py
@@ -29,7 +29,7 @@ class Client(http.HTTPClient):
"""
def __init__(self, *args, **kwargs):
- """ Initialize a new client for the Images v1 API. """
+ """Initialize a new client for the Images v1 API."""
super(Client, self).__init__(*args, **kwargs)
self.images = images.ImageManager(self)
self.image_members = image_members.ImageMemberManager(self)
diff --git a/glanceclient/v1/image_members.py b/glanceclient/v1/image_members.py
index a989850..1cb0f81 100644
--- a/glanceclient/v1/image_members.py
+++ b/glanceclient/v1/image_members.py
@@ -44,16 +44,16 @@ class ImageMemberManager(base.Manager):
if image and member:
try:
out.append(self.get(image, member))
- #TODO: narrow this down to 404
- except:
+ #TODO(bcwaldon): narrow this down to 404
+ except Exception:
pass
elif image:
out.extend(self._list_by_image(image))
elif member:
out.extend(self._list_by_member(member))
else:
- #TODO: figure out what is appropriate to do here as we are
- # unable to provide the requested response
+ #TODO(bcwaldon): figure out what is appropriate to do here as we
+ # are unable to provide the requested response
pass
return out
@@ -81,7 +81,7 @@ class ImageMemberManager(base.Manager):
self._delete("/v1/images/%s/members/%s" % (image_id, member_id))
def create(self, image, member_id, can_share=False):
- """Create an image"""
+ """Creates an image."""
url = '/v1/images/%s/members/%s' % (base.getid(image), member_id)
body = {'member': {'can_share': can_share}}
self._update(url, body=body)
diff --git a/glanceclient/v2/image_members.py b/glanceclient/v2/image_members.py
index a6a2d7e..784b571 100644
--- a/glanceclient/v2/image_members.py
+++ b/glanceclient/v2/image_members.py
@@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from glanceclient.common import utils
-
class Controller(object):
def __init__(self, http_client, model):
diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py
index f9aa01b..d7e0b3f 100644
--- a/glanceclient/v2/shell.py
+++ b/glanceclient/v2/shell.py
@@ -52,7 +52,7 @@ def do_image_show(gc, args):
@utils.arg('--image-id', metavar='<IMAGE_ID>', required=True,
help='Image to display members of.')
def do_member_list(gc, args):
- """Describe sharing permissions by image"""
+ """Describe sharing permissions by image."""
members = gc.image_members.list(args.image_id)
columns = ['Image ID', 'Member ID', 'Status']
diff --git a/run_tests.sh b/run_tests.sh
index dc6cf22..1b6551a 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -4,13 +4,13 @@ function usage {
echo "Usage: $0 [OPTION]..."
echo "Run python-glanceclient's test suite(s)"
echo ""
- echo " -p, --pep8 Just run pep8"
+ echo " -p, --pep8 Just run flake8"
echo " -h, --help Print this usage message"
echo ""
echo "This script is deprecated and currently retained for compatibility."
echo 'You can run the full test suite for multiple environments by running "tox".'
echo 'You can run tests for only python 2.7 by running "tox -e py27", or run only'
- echo 'the pep8 tests with "tox -e pep8".'
+ echo 'the flake8 tests with "tox -e pep8".'
exit
}
diff --git a/tests/test_exc.py b/tests/test_exc.py
index 5177556..b857aee 100644
--- a/tests/test_exc.py
+++ b/tests/test_exc.py
@@ -24,6 +24,6 @@ FakeResponse = collections.namedtuple('HTTPResponse', ['status'])
class TestHTTPExceptions(testtools.TestCase):
def test_from_response(self):
- """exc.from_response should return instance of an HTTP exception"""
+ """exc.from_response should return instance of an HTTP exception."""
out = exc.from_response(FakeResponse(400))
self.assertTrue(isinstance(out, exc.HTTPBadRequest))
diff --git a/tests/test_http.py b/tests/test_http.py
index d424cee..5cf84a5 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -61,7 +61,7 @@ class TestClient(testtools.TestCase):
# rather than assertRaises() so that we can check the body of
# the exception.
self.fail('An exception should have bypassed this line.')
- except exc.CommunicationError as comm_err:
+ except glanceclient.exc.CommunicationError as comm_err:
fail_msg = ("Exception message '%s' should contain '%s'" %
(comm_err.message, self.endpoint))
self.assertTrue(self.endpoint in comm_err.message, fail_msg)
diff --git a/tests/test_shell.py b/tests/test_shell.py
index f358546..a895c2d 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -16,9 +16,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import argparse
-import cStringIO
import os
-import sys
from glanceclient import exc
from glanceclient import shell as openstack_shell
diff --git a/tests/test_ssl.py b/tests/test_ssl.py
index 79c6389..60e1188 100644
--- a/tests/test_ssl.py
+++ b/tests/test_ssl.py
@@ -66,7 +66,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
conn = http.VerifiedHTTPSConnection('127.0.0.1', 0,
key_file=key_file,
cacert=cacert)
- except:
+ except Exception:
self.fail('Failed to init VerifiedHTTPSConnection.')
def test_ssl_init_bad_key(self):
@@ -126,7 +126,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
try:
conn = http.VerifiedHTTPSConnection('0.0.0.0', 0)
conn.verify_callback(None, cert, 0, 0, True)
- except:
+ except Exception:
self.fail('Unexpected exception.')
def test_ssl_cert_subject_alt_name(self):
@@ -141,13 +141,13 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
try:
conn = http.VerifiedHTTPSConnection('alt1.example.com', 0)
conn.verify_callback(None, cert, 0, 0, True)
- except:
+ except Exception:
self.fail('Unexpected exception.')
try:
conn = http.VerifiedHTTPSConnection('alt2.example.com', 0)
conn.verify_callback(None, cert, 0, 0, True)
- except:
+ except Exception:
self.fail('Unexpected exception.')
def test_ssl_cert_mismatch(self):
@@ -161,7 +161,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
self.assertEqual(cert.get_subject().commonName, '0.0.0.0')
try:
conn = http.VerifiedHTTPSConnection('mismatch.example.com', 0)
- except:
+ except Exception:
self.fail('Failed to init VerifiedHTTPSConnection.')
self.assertRaises(exc.SSLCertificateError,
@@ -179,7 +179,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase):
'openstack.example.com')
try:
conn = http.VerifiedHTTPSConnection('openstack.example.com', 0)
- except:
+ except Exception:
self.fail('Failed to init VerifiedHTTPSConnection.')
self.assertRaises(exc.SSLCertificateError,
diff --git a/tests/v1/test_shell.py b/tests/v1/test_shell.py
index 88ad3e3..cf4962d 100644
--- a/tests/v1/test_shell.py
+++ b/tests/v1/test_shell.py
@@ -300,7 +300,7 @@ class ShellInvalidEndpointTest(utils.TestCase):
class ShellStdinHandlingTests(testtools.TestCase):
def _fake_update_func(self, *args, **kwargs):
- ''' Function to replace glanceclient.images.update,
+ '''Function to replace glanceclient.images.update,
to determine the parameters that would be supplied with the update
request
'''
@@ -356,7 +356,7 @@ class ShellStdinHandlingTests(testtools.TestCase):
self.gc.images.update = self.real_update_func
def _do_update(self, image='96d2c7e1-de4e-4612-8aa2-ba26610c804e'):
- """call v1/shell's do_image_update function"""
+ """call v1/shell's do_image_update function."""
v1shell.do_image_update(
self.gc, argparse.Namespace(
@@ -410,7 +410,7 @@ class ShellStdinHandlingTests(testtools.TestCase):
try:
f.close()
os.remove(f.name)
- except:
+ except Exception:
pass
def test_image_update_data_is_read_from_pipe(self):
@@ -434,5 +434,5 @@ class ShellStdinHandlingTests(testtools.TestCase):
finally:
try:
process.stdout.close()
- except:
+ except OSError:
pass
diff --git a/tests/v2/test_members.py b/tests/v2/test_members.py
index 43f6530..6f2c9b0 100644
--- a/tests/v2/test_members.py
+++ b/tests/v2/test_members.py
@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-import errno
import testtools
import warlock
diff --git a/tox.ini b/tox.ini
index 318a363..dcbbe34 100644
--- a/tox.ini
+++ b/tox.ini
@@ -26,6 +26,10 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
downloadcache = ~/cache/pip
[flake8]
-ignore = F,H
+# H302 import only modules
+# H303 no wildcard import
+# H306 imports not in alphabetical orde
+# H404 multi line docstring should start with a summary
+ignore = F403,F841,F812,F821,H302,H303,H306,H404
show-source = True
exclude = .venv,.tox,dist,doc,*egg