Merge "Fix H501: Do not use locals() for string formatting"

This commit is contained in:
Jenkins 2013-08-13 13:51:04 +00:00 committed by Gerrit Code Review
commit d9c52956f5
11 changed files with 49 additions and 40 deletions

View File

@ -119,7 +119,7 @@ class FileTransfer(xfer_base.TransferBase):
if r not in metadata:
url = url_parts.geturl()
msg = _('The key %(r)s is required in the location metadata '
'to access the url %(url)s.') % locals()
'to access the url %(url)s.') % {'r': r, 'url': url}
LOG.info(msg)
raise exception.ImageDownloadModuleMetaDataError(
module=str(self), reason=msg)
@ -128,8 +128,9 @@ class FileTransfer(xfer_base.TransferBase):
def _normalize_destination(self, nova_mount, glance_mount, path):
if not path.startswith(glance_mount):
msg = _('The mount point advertised by glance: %(glance_mount)s, '
'does not match the URL path: %(path)s') % locals()
msg = (_('The mount point advertised by glance: %(glance_mount)s, '
'does not match the URL path: %(path)s') %
{'glance_mount': glance_mount, 'path': path})
raise exception.ImageDownloadModuleMetaDataError(
module=str(self), reason=msg)
new_path = path.replace(glance_mount, nova_mount, 1)

View File

@ -311,7 +311,7 @@ class GlanceImageService(object):
return None
except Exception as ex:
LOG.error(_("Failed to instantiate the download handler "
"for %(scheme)s") % locals())
"for %(scheme)s") % {'scheme': scheme})
return
def download(self, context, image_id, data=None):

View File

@ -140,8 +140,7 @@ class AdminActionsTest(test.TestCase):
req.content_type = 'application/json'
res = req.get_response(app)
self.assertEqual(res.status_int, 409)
self.assertIn("Cannot \'%(_action)s\' while instance" % locals(),
res.body)
self.assertIn("Cannot \'%s\' while instance" % _action, res.body)
def test_admin_api_actions_raise_not_found(self):
app = fakes.wsgi_app(init_only=('servers',))

View File

@ -152,8 +152,7 @@ class AdminActionsTest(test.TestCase):
res = self._make_request('/v3/servers/%s/action' % self.UUID,
{_action: None})
self.assertEqual(res.status_int, 409)
self.assertIn("Cannot \'%(_action)s\' while instance" % locals(),
res.body)
self.assertIn("Cannot \'%s\' while instance" % _action, res.body)
def test_admin_api_actions_with_non_existed_instance(self):
app = fakes.wsgi_app_v3(init_only=('servers', 'os-admin-actions'))

View File

@ -433,7 +433,7 @@ class BaseTrackerTestCase(BaseTestCase):
if field not in tracker.compute_node:
raise test.TestingException(
"'%(field)s' not in compute node." % locals())
"'%(field)s' not in compute node." % {'field': field})
x = tracker.compute_node[field]
self.assertEqual(value, x)

View File

@ -86,8 +86,7 @@ def _get_connect_string(backend, user, passwd, database):
else:
raise Exception("Unrecognized backend: '%s'" % backend)
return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
% locals())
return ("%s://%s:%s@localhost/%s" % (backend, user, passwd, database))
def _is_backend_avail(backend, user, passwd, database):
@ -262,13 +261,14 @@ class BaseMigrationTestCase(test.TestCase):
# operations there is a special database template1.
sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
" '%(sql)s' -d template1")
sqldict = {'user': user, 'host': host}
sql = ("drop database if exists %(database)s;") % locals()
droptable = sqlcmd % locals()
sqldict['sql'] = ("drop database if exists %s;") % database
droptable = sqlcmd % sqldict
self.execute_cmd(droptable)
sql = ("create database %(database)s;") % locals()
createtable = sqlcmd % locals()
sqldict['sql'] = ("create database %s;") % database
createtable = sqlcmd % sqldict
self.execute_cmd(createtable)
os.unsetenv('PGPASSWORD')
@ -294,9 +294,11 @@ class BaseMigrationTestCase(test.TestCase):
(user, password, database, host) = \
get_mysql_connection_info(conn_pieces)
sql = ("drop database if exists %(database)s; "
"create database %(database)s;") % locals()
"create database %(database)s;"
% {'database': database})
cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s "
"-e \"%(sql)s\"") % locals()
"-e \"%(sql)s\"" % {'user': user,
'password': password, 'host': host, 'sql': sql})
self.execute_cmd(cmd)
elif conn_string.startswith('postgresql'):
self._reset_pg(conn_pieces)
@ -324,7 +326,7 @@ class BaseMigrationTestCase(test.TestCase):
total = connection.execute("SELECT count(*) "
"from information_schema.TABLES "
"where TABLE_SCHEMA='%(database)s'" %
locals())
{'database': database})
self.assertTrue(total.scalar() > 0, "No tables found. Wrong schema?")
noninnodb = connection.execute("SELECT count(*) "
@ -332,7 +334,7 @@ class BaseMigrationTestCase(test.TestCase):
"where TABLE_SCHEMA='%(database)s' "
"and ENGINE!='InnoDB' "
"and TABLE_NAME!='migrate_version'" %
locals())
{'database': database})
count = noninnodb.scalar()
self.assertEqual(count, 0, "%d non InnoDB tables created" % count)
connection.close()

View File

@ -96,10 +96,8 @@ def fake_execute(*cmd_parts, **kwargs):
LOG.debug(_('Faked command raised an exception %s'), e)
raise
stdout = reply[0]
stderr = reply[1]
LOG.debug(_("Reply to faked command is stdout='%(stdout)s' "
"stderr='%(stderr)s'") % locals())
"stderr='%(stderr)s'") % {'stdout': reply[0], 'stderr': reply[1]})
# Replicate the sleep call in the real function
greenthread.sleep(0)

View File

@ -36,8 +36,10 @@ class OpenStackApiException(Exception):
_status = response.status
_body = response.read()
message = _('%(message)s\nStatus Code: %(_status)s\n'
'Body: %(_body)s') % locals()
message = (_('%(message)s\nStatus Code: %(_status)s\n'
'Body: %(_body)s') %
{'message': message, '_status': _status,
'_body': _body})
super(OpenStackApiException, self).__init__(message)
@ -103,7 +105,8 @@ class TestOpenStackClient(object):
relative_url = parsed_url.path
if parsed_url.query:
relative_url = relative_url + "?" + parsed_url.query
LOG.info(_("Doing %(method)s on %(relative_url)s") % locals())
LOG.info(_("Doing %(method)s on %(relative_url)s") %
{'method': method, 'relative_url': relative_url})
if body:
LOG.info(_("Body: %s") % body)
@ -123,7 +126,8 @@ class TestOpenStackClient(object):
headers=headers)
http_status = response.status
LOG.debug(_("%(auth_uri)s => code %(http_status)s") % locals())
LOG.debug(_("%(auth_uri)s => code %(http_status)s") %
{'auth_uri': auth_uri, 'http_status': http_status})
if http_status == 401:
raise OpenStackApiAuthenticationException(response=response)
@ -153,7 +157,8 @@ class TestOpenStackClient(object):
response = self.request(full_uri, **kwargs)
http_status = response.status
LOG.debug(_("%(relative_uri)s => code %(http_status)s") % locals())
LOG.debug(_("%(relative_uri)s => code %(http_status)s") %
{'relative_uri': relative_uri, 'http_status': http_status})
if check_response_status:
if http_status not in check_response_status:

View File

@ -185,7 +185,7 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
if isinstance(expected, dict):
if not isinstance(result, dict):
raise NoMatch(_('%(result_str)s: %(result)s is not a dict.')
% locals())
% {'result_str': result_str, 'result': result})
ex_keys = sorted(expected.keys())
res_keys = sorted(result.keys())
if ex_keys != res_keys:
@ -200,8 +200,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
raise NoMatch(
_('Dictionary key mismatch:\n'
'Extra key(s) in template:\n%(ex_delta)s\n'
'Extra key(s) in %(result_str)s:\n%(res_delta)s\n')
% locals())
'Extra key(s) in %(result_str)s:\n%(res_delta)s\n') %
{'ex_delta': ex_delta, 'result_str': result_str,
'res_delta': res_delta})
for key in ex_keys:
res = self._compare_result(subs, expected[key], result[key],
result_str)
@ -209,7 +210,8 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
elif isinstance(expected, list):
if not isinstance(result, list):
raise NoMatch(
_('%(result_str)s: %(result)s is not a list.') % locals())
_('%(result_str)s: %(result)s is not a list.') %
{'result_str': result_str, 'result': result})
expected = expected[:]
extra = []
@ -232,8 +234,8 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
error.extend([repr(o) for o in expected])
if extra:
error.append(_('Extra list items in %(result_str)s:')
% locals())
error.append(_('Extra list items in %(result_str)s:') %
{'result_str': result_str})
error.extend([repr(o) for o in extra])
if error:
@ -254,8 +256,9 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
if not match:
raise NoMatch(
_('Values do not match:\n'
'Template: %(expected)s\n%(result_str)s: %(result)s')
% locals())
'Template: %(expected)s\n%(result_str)s: %(result)s') %
{'expected': expected, 'result_str': result_str,
'result': result})
try:
matched_value = match.group('id')
except IndexError:
@ -269,8 +272,10 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
if expected != result:
raise NoMatch(
_('Values do not match:\n'
'Template: %(expected)s\n%(result_str)s: %(result)s')
% locals())
'Template: %(expected)s\n%(result_str)s: '
'%(result)s') % {'expected': expected,
'result_str': result_str,
'result': result})
return matched_value
def generalize_subs(self, subs, vanilla_regexes):

View File

@ -825,7 +825,8 @@ class PowerVMDriverLparTestCase(test.TestCase):
exp_mac_str = mac[:-2].replace(':', '')
exp_cmd = ('chsyscfg -r lpar -i "name=%(inst_name)s, '
'virtual_eth_mac_base_value=%(exp_mac_str)s"') % locals()
'virtual_eth_mac_base_value=%(exp_mac_str)s"'
% {'inst_name': inst_name, 'exp_mac_str': exp_mac_str})
fake_op = self.powervm_connection._powervm
self.mox.StubOutWithMock(fake_op._operator, 'run_vios_command')

View File

@ -45,9 +45,8 @@ commands = {posargs}
# in sqlalchemy.
# TODO Hacking 0.6 checks to fix
# H102 Apache 2.0 license header not found
# H501 Do not use locals() for string formatting
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H302,H404,F403,H501,F811,F841
ignore = E121,E122,E123,E124,E126,E127,E128,E711,E712,H102,H302,H404,F403,F811,F841
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,*plugins/xenserver*,tools
[hacking]