Browse Source

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
changes/10/32310/3
Dirk Mueller 8 years ago
parent
commit
62579fbb21
  1. 5
      glanceclient/common/http.py
  2. 24
      glanceclient/exc.py
  3. 2
      glanceclient/openstack/common/importutils.py
  4. 2
      glanceclient/shell.py
  5. 2
      glanceclient/v1/__init__.py
  6. 2
      glanceclient/v1/client.py
  7. 10
      glanceclient/v1/image_members.py
  8. 2
      glanceclient/v2/image_members.py
  9. 2
      glanceclient/v2/shell.py
  10. 4
      run_tests.sh
  11. 2
      tests/test_exc.py
  12. 2
      tests/test_http.py
  13. 2
      tests/test_shell.py
  14. 12
      tests/test_ssl.py
  15. 8
      tests/v1/test_shell.py
  16. 1
      tests/v2/test_members.py
  17. 6
      tox.ini

5
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.

24
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

2
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)

2
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('/'):

2
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

2
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)

10
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)

2
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):

2
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']

4
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
}

2
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))

2
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)

2
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

12
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,

8
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

1
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

6
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
Loading…
Cancel
Save