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:
@@ -462,10 +462,10 @@ class Server(object):
|
|||||||
# maybe there's a config file(s) out there, but I couldn't find it!
|
# maybe there's a config file(s) out there, but I couldn't find it!
|
||||||
if not kwargs.get('quiet'):
|
if not kwargs.get('quiet'):
|
||||||
if number:
|
if number:
|
||||||
print(_('Unable to locate config number %s for %s' % (
|
print(_('Unable to locate config number %s for %s')
|
||||||
number, self.server)))
|
% (number, self.server))
|
||||||
else:
|
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 kwargs.get('verbose') and not kwargs.get('quiet'):
|
||||||
if found_conf_files:
|
if found_conf_files:
|
||||||
print(_('Found configs:'))
|
print(_('Found configs:'))
|
||||||
|
@@ -331,7 +331,7 @@ class ObjectAuditor(Daemon):
|
|||||||
try:
|
try:
|
||||||
self.audit_loop(parent, zbo_fps, **kwargs)
|
self.audit_loop(parent, zbo_fps, **kwargs)
|
||||||
except (Exception, Timeout) as err:
|
except (Exception, Timeout) as err:
|
||||||
self.logger.exception(_('ERROR auditing: %s' % err))
|
self.logger.exception(_('ERROR auditing: %s'), err)
|
||||||
self._sleep()
|
self._sleep()
|
||||||
|
|
||||||
def run_once(self, *args, **kwargs):
|
def run_once(self, *args, **kwargs):
|
||||||
@@ -352,4 +352,4 @@ class ObjectAuditor(Daemon):
|
|||||||
self.audit_loop(parent, zbo_fps, override_devices=override_devices,
|
self.audit_loop(parent, zbo_fps, override_devices=override_devices,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
except (Exception, Timeout) as err:
|
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):
|
class Bogus(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
loop_error = Bogus('exception')
|
||||||
|
|
||||||
class ObjectAuditorMock(object):
|
class ObjectAuditorMock(object):
|
||||||
check_args = ()
|
check_args = ()
|
||||||
check_kwargs = {}
|
check_kwargs = {}
|
||||||
@@ -568,7 +570,7 @@ class TestAuditor(unittest.TestCase):
|
|||||||
|
|
||||||
def mock_audit_loop_error(self, parent, zbo_fps,
|
def mock_audit_loop_error(self, parent, zbo_fps,
|
||||||
override_devices=None, **kwargs):
|
override_devices=None, **kwargs):
|
||||||
raise Bogus('exception')
|
raise loop_error
|
||||||
|
|
||||||
def mock_fork(self):
|
def mock_fork(self):
|
||||||
self.fork_called += 1
|
self.fork_called += 1
|
||||||
@@ -602,11 +604,11 @@ class TestAuditor(unittest.TestCase):
|
|||||||
my_auditor._sleep = mocker.mock_sleep_stop
|
my_auditor._sleep = mocker.mock_sleep_stop
|
||||||
my_auditor.run_once(zero_byte_fps=50)
|
my_auditor.run_once(zero_byte_fps=50)
|
||||||
my_auditor.logger.exception.assert_called_once_with(
|
my_auditor.logger.exception.assert_called_once_with(
|
||||||
'ERROR auditing: exception')
|
'ERROR auditing: %s', loop_error)
|
||||||
my_auditor.logger.exception.reset_mock()
|
my_auditor.logger.exception.reset_mock()
|
||||||
self.assertRaises(StopForever, my_auditor.run_forever)
|
self.assertRaises(StopForever, my_auditor.run_forever)
|
||||||
my_auditor.logger.exception.assert_called_once_with(
|
my_auditor.logger.exception.assert_called_once_with(
|
||||||
'ERROR auditing: exception')
|
'ERROR auditing: %s', loop_error)
|
||||||
my_auditor.audit_loop = real_audit_loop
|
my_auditor.audit_loop = real_audit_loop
|
||||||
|
|
||||||
self.assertRaises(StopForever,
|
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
|
# H404: multi line docstring should start without a leading new line
|
||||||
# H405: multi line docstring summary not separated with an empty line
|
# H405: multi line docstring summary not separated with an empty line
|
||||||
# H501: Do not use self.__dict__ for string formatting
|
# H501: Do not use self.__dict__ for string formatting
|
||||||
# H702: Formatting operation should be outside of localization method call
|
|
||||||
# H703: Multiple positional placeholders
|
# 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
|
exclude = .venv,.tox,dist,doc,*egg
|
||||||
show-source = True
|
show-source = True
|
||||||
|
Reference in New Issue
Block a user