44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from tacker.hacking import checks
|
|
from tacker.tests import base
|
|
|
|
|
|
class HackingTestCase(base.BaseTestCase):
|
|
|
|
def test_log_translations(self):
|
|
logs = ['audit', 'error', 'info', 'warn', 'warning', 'critical',
|
|
'exception']
|
|
levels = ['_LI', '_LW', '_LE', '_LC']
|
|
debug = "LOG.debug('OK')"
|
|
self.assertEqual(
|
|
0, len(list(checks.validate_log_translations(debug, debug, 'f'))))
|
|
for log in logs:
|
|
bad = 'LOG.%s("Bad")' % log
|
|
self.assertEqual(
|
|
1, len(list(checks.validate_log_translations(bad, bad, 'f'))))
|
|
ok = "LOG.%s(_('OK'))" % log
|
|
self.assertEqual(
|
|
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
|
|
ok = "LOG.%s('OK') # noqa" % log
|
|
self.assertEqual(
|
|
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
|
|
ok = "LOG.%s(variable)" % log
|
|
self.assertEqual(
|
|
0, len(list(checks.validate_log_translations(ok, ok, 'f'))))
|
|
for level in levels:
|
|
ok = "LOG.%s(%s('OK'))" % (log, level)
|
|
self.assertEqual(
|
|
0, len(list(checks.validate_log_translations(ok,
|
|
ok, 'f'))))
|