From 2a08054f8ce5b1ed00085a269cd1a62a8a7164b7 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Mon, 20 May 2013 14:08:03 +1000 Subject: [PATCH] Fix some "H" pep errors And be more specific about which ones we ignore. Change-Id: I69fd6897957e3dcb5939cf48651a0f1b41b711dd --- heatclient/common/http.py | 4 ++-- heatclient/exc.py | 22 ++++++++++---------- heatclient/shell.py | 2 +- heatclient/v1/client.py | 2 +- heatclient/v1/shell.py | 42 +++++++++++++++++++-------------------- heatclient/v1/stacks.py | 6 +++--- tests/fakes.py | 2 +- tests/test_common_http.py | 8 ++------ tests/test_shell.py | 8 ++++---- tests/test_utils.py | 2 +- tox.ini | 2 +- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/heatclient/common/http.py b/heatclient/common/http.py index e7591218..9cdf6db8 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -121,7 +121,7 @@ class HTTPClient(object): LOG.debug('\n'.join(dump)) 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. @@ -256,7 +256,7 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection): @staticmethod def get_system_ca_file(): - """"Return path to system default CA file""" + """Return path to system default CA file.""" # Standard CA file locations for Debian/Ubuntu, RedHat/Fedora, # Suse, FreeBSD/OpenBSD ca_path = ['/etc/ssl/certs/ca-certificates.crt', diff --git a/heatclient/exc.py b/heatclient/exc.py index 7d32bc10..c90b0fc5 100644 --- a/heatclient/exc.py +++ b/heatclient/exc.py @@ -23,7 +23,7 @@ class BaseException(Exception): class CommandError(BaseException): - """Invalid usage of CLI""" + """Invalid usage of CLI.""" class InvalidEndpoint(BaseException): @@ -35,7 +35,7 @@ class CommunicationError(BaseException): class HTTPException(BaseException): - """Base exception for all HTTP-derived exceptions""" + """Base exception for all HTTP-derived exceptions.""" code = 'N/A' @@ -50,7 +50,7 @@ class HTTPMultipleChoices(HTTPException): class BadRequest(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 400 @@ -59,7 +59,7 @@ class HTTPBadRequest(BadRequest): class Unauthorized(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 401 @@ -68,7 +68,7 @@ class HTTPUnauthorized(Unauthorized): class Forbidden(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 403 @@ -77,7 +77,7 @@ class HTTPForbidden(Forbidden): class NotFound(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 404 @@ -90,7 +90,7 @@ class HTTPMethodNotAllowed(HTTPException): class Conflict(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 409 @@ -99,7 +99,7 @@ class HTTPConflict(Conflict): class OverLimit(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 413 @@ -120,7 +120,7 @@ class HTTPBadGateway(HTTPException): class ServiceUnavailable(HTTPException): - """DEPRECATED""" + """DEPRECATED.""" code = 503 @@ -145,10 +145,10 @@ def from_response(response, body_iter): class NoTokenLookupException(Exception): - """DEPRECATED""" + """DEPRECATED.""" pass class EndpointNotFound(Exception): - """DEPRECATED""" + """DEPRECATED.""" pass diff --git a/heatclient/shell.py b/heatclient/shell.py index 3e6c72e0..9c4ca644 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -21,9 +21,9 @@ import sys from keystoneclient.v2_0 import client as ksclient -from heatclient import exc from heatclient import client as heatclient from heatclient.common import utils +from heatclient import exc logger = logging.getLogger(__name__) diff --git a/heatclient/v1/client.py b/heatclient/v1/client.py index 2742728c..f44208d4 100644 --- a/heatclient/v1/client.py +++ b/heatclient/v1/client.py @@ -30,7 +30,7 @@ class Client(http.HTTPClient): """ def __init__(self, *args, **kwargs): - """ Initialize a new client for the Heat v1 API. """ + """Initialize a new client for the Heat v1 API.""" super(Client, self).__init__(*args, **kwargs) self.stacks = stacks.StackManager(self) self.resources = resources.ResourceManager(self) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 9d7f0b46..736ae6a3 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -58,7 +58,7 @@ def _set_template_fields(hc, args, fields): @utils.arg('name', metavar='', help='Name of the stack to create.') def do_create(hc, args): - '''DEPRECATED! Use stack-create instead''' + '''DEPRECATED! Use stack-create instead.''' do_stack_create(hc, args) @@ -78,7 +78,7 @@ def do_create(hc, args): @utils.arg('name', metavar='', help='Name of the stack to create.') def do_stack_create(hc, args): - '''Create the stack''' + '''Create the stack.''' fields = {'stack_name': args.name, 'timeout_mins': args.create_timeout, 'disable_rollback': not(args.enable_rollback), @@ -91,13 +91,13 @@ def do_stack_create(hc, args): @utils.arg('id', metavar='', help='Name or ID of stack to delete.') def do_delete(hc, args): - '''DEPRECATED! Use stack-delete instead''' + '''DEPRECATED! Use stack-delete instead.''' do_stack_delete(hc, args) @utils.arg('id', metavar='', help='Name or ID of stack to delete.') def do_stack_delete(hc, args): - '''Delete the stack''' + '''Delete the stack.''' fields = {'stack_id': args.id} try: hc.stacks.delete(**fields) @@ -110,14 +110,14 @@ def do_stack_delete(hc, args): @utils.arg('id', metavar='', help='Name or ID of stack to describe.') def do_describe(hc, args): - '''DEPRECATED! Use stack-show instead''' + '''DEPRECATED! Use stack-show instead.''' do_stack_show(hc, args) @utils.arg('id', metavar='', help='Name or ID of stack to describe.') def do_stack_show(hc, args): - '''Describe the stack''' + '''Describe the stack.''' fields = {'stack_id': args.id} try: stack = hc.stacks.get(**fields) @@ -149,7 +149,7 @@ def do_stack_show(hc, args): @utils.arg('id', metavar='', help='Name or ID of stack to update.') def do_update(hc, args): - '''DEPRECATED! Use stack-update instead''' + '''DEPRECATED! Use stack-update instead.''' do_stack_update(hc, args) @@ -164,7 +164,7 @@ def do_update(hc, args): @utils.arg('id', metavar='', help='Name or ID of stack to update.') def do_stack_update(hc, args): - '''Update the stack''' + '''Update the stack.''' fields = {'stack_id': args.id, 'parameters': utils.format_parameters(args.parameters)} _set_template_fields(hc, args, fields) @@ -174,12 +174,12 @@ def do_stack_update(hc, args): def do_list(hc, args={}): - '''DEPRECATED! Use stack-list instead''' + '''DEPRECATED! Use stack-list instead.''' do_stack_list(hc, args) def do_stack_list(hc, args={}): - '''List the user's stacks''' + '''List the user's stacks.''' kwargs = {} stacks = hc.stacks.list(**kwargs) fields = ['id', 'stack_name', 'stack_status', 'creation_time'] @@ -189,14 +189,14 @@ def do_stack_list(hc, args={}): @utils.arg('id', metavar='', help='Name or ID of stack to get the template for.') def do_gettemplate(hc, args): - '''DEPRECATED! Use template-show instead''' + '''DEPRECATED! Use template-show instead.''' do_template_show(hc, args) @utils.arg('id', metavar='', help='Name or ID of stack to get the template for.') def do_template_show(hc, args): - '''Get the template for the specified stack''' + '''Get the template for the specified stack.''' fields = {'stack_id': args.id} try: template = hc.stacks.template(**fields) @@ -215,7 +215,7 @@ def do_template_show(hc, args): @utils.arg('-P', '--parameters', metavar='', help='Parameter values to validate.') def do_validate(hc, args): - '''DEPRECATED! Use template-validate instead''' + '''DEPRECATED! Use template-validate instead.''' do_template_validate(hc, args) @@ -228,7 +228,7 @@ def do_validate(hc, args): @utils.arg('-P', '--parameters', metavar='', help='Parameter values to validate.') def do_template_validate(hc, args): - '''Validate a template with parameters''' + '''Validate a template with parameters.''' fields = {'parameters': utils.format_parameters(args.parameters)} _set_template_fields(hc, args, fields) @@ -239,7 +239,7 @@ def do_template_validate(hc, args): @utils.arg('id', metavar='', help='Name or ID of stack to show the resources for.') def do_resource_list(hc, args): - '''Show list of resources belonging to a stack''' + '''Show list of resources belonging to a stack.''' fields = {'stack_id': args.id} try: resources = hc.resources.list(**fields) @@ -256,7 +256,7 @@ def do_resource_list(hc, args): @utils.arg('resource', metavar='', help='Name of the resource to show the details for.') def do_resource(hc, args): - '''DEPRECATED! Use resource-show instead''' + '''DEPRECATED! Use resource-show instead.''' do_resource_show(hc, args) @@ -265,7 +265,7 @@ def do_resource(hc, args): @utils.arg('resource', metavar='', help='Name of the resource to show the details for.') def do_resource_show(hc, args): - '''Describe the resource''' + '''Describe the resource.''' fields = {'stack_id': args.id, 'resource_name': args.resource} try: @@ -287,7 +287,7 @@ def do_resource_show(hc, args): @utils.arg('resource', metavar='', help='Name of the resource to show the metadata for.') def do_resource_metadata(hc, args): - '''List resource metadata''' + '''List resource metadata.''' fields = {'stack_id': args.id, 'resource_name': args.resource} try: @@ -304,7 +304,7 @@ def do_resource_metadata(hc, args): @utils.arg('-r', '--resource', metavar='', help='Name of the resource to filter events by') def do_event_list(hc, args): - '''List events for a stack''' + '''List events for a stack.''' fields = {'stack_id': args.id, 'resource_name': args.resource} try: @@ -324,7 +324,7 @@ def do_event_list(hc, args): @utils.arg('event', metavar='', help='ID of event to display details for') def do_event(hc, args): - '''DEPRECATED! Use event-show instead''' + '''DEPRECATED! Use event-show instead.''' do_event_show(hc, args) @@ -335,7 +335,7 @@ def do_event(hc, args): @utils.arg('event', metavar='', help='ID of event to display details for') def do_event_show(hc, args): - '''Describe the event''' + '''Describe the event.''' fields = {'stack_id': args.id, 'resource_name': args.resource, 'event_id': args.event} diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index 27d6466d..565de94c 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -81,12 +81,12 @@ class StackManager(base.Manager): return paginate(params) def create(self, **kwargs): - """Create a stack""" + """Create a stack.""" resp, body = self.api.json_request( 'POST', '/stacks', body=kwargs) def update(self, **kwargs): - """Update a stack""" + """Update a stack.""" stack_id = kwargs.pop('stack_id') resp, body = self.api.json_request( 'PUT', '/stacks/%s' % stack_id, body=kwargs) @@ -114,7 +114,7 @@ class StackManager(base.Manager): return body def validate(self, **kwargs): - """Validate a stack template""" + """Validate a stack template.""" resp, body = self.api.json_request( 'POST', '/validate', body=kwargs) return body diff --git a/tests/fakes.py b/tests/fakes.py index 96034ea1..653b91cc 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -1,7 +1,7 @@ import json -from keystoneclient.v2_0 import client as ksclient from heatclient.v1 import client as v1client +from keystoneclient.v2_0 import client as ksclient def script_keystone_client(): diff --git a/tests/test_common_http.py b/tests/test_common_http.py index aa26e9ec..28109fde 100644 --- a/tests/test_common_http.py +++ b/tests/test_common_http.py @@ -1,9 +1,9 @@ import mox import unittest -from heatclient import exc -from heatclient.common import http import fakes +from heatclient.common import http +from heatclient import exc class HttpClientTest(unittest.TestCase): @@ -195,8 +195,6 @@ class HttpClientTest(unittest.TestCase): except exc.HTTPNotFound as e: # Assert that the raised exception can be converted to string self.assertNotEqual(e.message, None) - except: - raise self.m.VerifyAll() def test_http_300_json_request(self): @@ -220,8 +218,6 @@ class HttpClientTest(unittest.TestCase): except exc.HTTPMultipleChoices as e: # Assert that the raised exception can be converted to string self.assertNotEqual(e.message, None) - except: - raise self.m.VerifyAll() #def test_https_json_request(self): diff --git a/tests/test_shell.py b/tests/test_shell.py index 0fe890e6..32a1a1d5 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -1,6 +1,6 @@ import cStringIO -import os import httplib2 +import os import re import sys @@ -12,10 +12,10 @@ except ImportError: import simplejson as json from keystoneclient.v2_0 import client as ksclient -from heatclient import exc -from heatclient.v1 import client as v1client -import heatclient.shell import fakes +from heatclient import exc +import heatclient.shell +from heatclient.v1 import client as v1client TEST_VAR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'var')) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4aff609e..8a8d08ad 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -12,8 +12,8 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import unittest from heatclient.common import utils +import unittest class shellTest(unittest.TestCase): diff --git a/tox.ini b/tox.ini index 405ddf58..f70bc792 100644 --- a/tox.ini +++ b/tox.ini @@ -26,6 +26,6 @@ downloadcache = ~/cache/pip [flake8] show-source = True -ignore = E12,H,F403,F821,F841 +ignore = E12,H302,H303,H304,H403,H404,F403,F821,F841 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg