diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-10-11 17:55:32 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-10-11 17:55:32 +0000 |
commit | cbbe486cd961e7f002c6e9ebdfdfa10527aa6b03 (patch) | |
tree | 1e324cc58c588df38fd983980535f0eb30353692 /nova/tests/unit/test_hacking.py | |
parent | 6974d651ccbbf91ec5850af1c7c66cea627744d3 (diff) | |
parent | 4eb89c206e68a7172ebad897ad24769036c7bdd6 (diff) | |
download | nova-cbbe486cd961e7f002c6e9ebdfdfa10527aa6b03.tar.gz |
Merge "Add a hacking rule for string interpolation at logging"
Diffstat (limited to 'nova/tests/unit/test_hacking.py')
-rw-r--r-- | nova/tests/unit/test_hacking.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/nova/tests/unit/test_hacking.py b/nova/tests/unit/test_hacking.py index 9ceb2a2936..ced94f0161 100644 --- a/nova/tests/unit/test_hacking.py +++ b/nova/tests/unit/test_hacking.py @@ -792,3 +792,54 @@ class HackingTestCase(test.NoDBTestCase): instance=instance) """ self._assert_has_no_errors(code, checks.check_context_log) + + def test_check_delayed_string_interpolation(self): + checker = checks.check_delayed_string_interpolation + code = """ + msg_w = _LW('Test string (%s)') + msg_i = _LI('Test string (%s)') + value = 'test' + + LOG.error(_LE("Test string (%s)") % value) + LOG.warning(msg_w % 'test%string') + LOG.info(msg_i % + "test%string%info") + LOG.critical( + _LC('Test string (%s)') % value, + instance=instance) + LOG.exception(_LE(" 'Test quotation %s' \"Test\"") % 'test') + LOG.debug(' "Test quotation %s" \'Test\'' % "test") + LOG.debug('Tesing %(test)s' % + {'test': ','.join( + ['%s=%s' % (name, value) + for name, value in test.items()])}) + """ + + expected_errors = [(5, 34, 'N354'), (6, 18, 'N354'), (7, 15, 'N354'), + (10, 28, 'N354'), (12, 49, 'N354'), + (13, 40, 'N354'), (14, 28, 'N354')] + self._assert_has_errors(code, checker, expected_errors=expected_errors) + self._assert_has_no_errors(code, checker, + filename='nova/tests/unit/test_hacking.py') + + code = """ + msg_w = _LW('Test string (%s)') + msg_i = _LI('Test string (%s)') + value = 'test' + + LOG.error(_LE("Test string (%s)"), value) + LOG.error(_LE("Test string (%s)") % value) # noqa + LOG.warning(msg_w, 'test%string') + LOG.info(msg_i, + "test%string%info") + LOG.critical( + _LC('Test string (%s)'), value, + instance=instance) + LOG.exception(_LE(" 'Test quotation %s' \"Test\""), 'test') + LOG.debug(' "Test quotation %s" \'Test\'', "test") + LOG.debug('Tesing %(test)s', + {'test': ','.join( + ['%s=%s' % (name, value) + for name, value in test.items()])}) + """ + self._assert_has_no_errors(code, checker) |