pep8: Fix usage of the l10n _('...') function
Fix the pep8 warning H702 "Formatting operation should be outside of localization method call". For the logger, pass parameters as indexed parameters instead of using the string str%args operator, the logger is more reliable in case of formatting error. Change-Id: If418bc155f6a6c0a00f63e3d87ebe4addf4aae55
This commit is contained in:
parent
7bea148d2f
commit
c7eb589c6c
@ -462,10 +462,10 @@ class Server(object):
|
||||
# maybe there's a config file(s) out there, but I couldn't find it!
|
||||
if not kwargs.get('quiet'):
|
||||
if number:
|
||||
print(_('Unable to locate config number %s for %s' % (
|
||||
number, self.server)))
|
||||
print(_('Unable to locate config number %s for %s')
|
||||
% (number, self.server))
|
||||
else:
|
||||
print(_('Unable to locate config for %s' % (self.server)))
|
||||
print(_('Unable to locate config for %s') % self.server)
|
||||
if kwargs.get('verbose') and not kwargs.get('quiet'):
|
||||
if found_conf_files:
|
||||
print(_('Found configs:'))
|
||||
|
@ -331,7 +331,7 @@ class ObjectAuditor(Daemon):
|
||||
try:
|
||||
self.audit_loop(parent, zbo_fps, **kwargs)
|
||||
except (Exception, Timeout) as err:
|
||||
self.logger.exception(_('ERROR auditing: %s' % err))
|
||||
self.logger.exception(_('ERROR auditing: %s'), err)
|
||||
self._sleep()
|
||||
|
||||
def run_once(self, *args, **kwargs):
|
||||
@ -352,4 +352,4 @@ class ObjectAuditor(Daemon):
|
||||
self.audit_loop(parent, zbo_fps, override_devices=override_devices,
|
||||
**kwargs)
|
||||
except (Exception, Timeout) as err:
|
||||
self.logger.exception(_('ERROR auditing: %s' % err))
|
||||
self.logger.exception(_('ERROR auditing: %s'), err)
|
||||
|
@ -546,6 +546,8 @@ class TestAuditor(unittest.TestCase):
|
||||
class Bogus(Exception):
|
||||
pass
|
||||
|
||||
loop_error = Bogus('exception')
|
||||
|
||||
class ObjectAuditorMock(object):
|
||||
check_args = ()
|
||||
check_kwargs = {}
|
||||
@ -568,7 +570,7 @@ class TestAuditor(unittest.TestCase):
|
||||
|
||||
def mock_audit_loop_error(self, parent, zbo_fps,
|
||||
override_devices=None, **kwargs):
|
||||
raise Bogus('exception')
|
||||
raise loop_error
|
||||
|
||||
def mock_fork(self):
|
||||
self.fork_called += 1
|
||||
@ -602,11 +604,11 @@ class TestAuditor(unittest.TestCase):
|
||||
my_auditor._sleep = mocker.mock_sleep_stop
|
||||
my_auditor.run_once(zero_byte_fps=50)
|
||||
my_auditor.logger.exception.assert_called_once_with(
|
||||
'ERROR auditing: exception')
|
||||
'ERROR auditing: %s', loop_error)
|
||||
my_auditor.logger.exception.reset_mock()
|
||||
self.assertRaises(StopForever, my_auditor.run_forever)
|
||||
my_auditor.logger.exception.assert_called_once_with(
|
||||
'ERROR auditing: exception')
|
||||
'ERROR auditing: %s', loop_error)
|
||||
my_auditor.audit_loop = real_audit_loop
|
||||
|
||||
self.assertRaises(StopForever,
|
||||
|
3
tox.ini
3
tox.ini
@ -68,8 +68,7 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate
|
||||
# H404: multi line docstring should start without a leading new line
|
||||
# H405: multi line docstring summary not separated with an empty line
|
||||
# H501: Do not use self.__dict__ for string formatting
|
||||
# H702: Formatting operation should be outside of localization method call
|
||||
# H703: Multiple positional placeholders
|
||||
ignore = F402,F812,H101,H202,H233,H234,H301,H306,H401,H403,H404,H405,H501,H702,H703
|
||||
ignore = F402,F812,H101,H202,H233,H234,H301,H306,H401,H403,H404,H405,H501,H703
|
||||
exclude = .venv,.tox,dist,doc,*egg
|
||||
show-source = True
|
||||
|
Loading…
Reference in New Issue
Block a user