Exemplo n.º 1
0
    def test_log_translations(self):
        expected_marks = {
            'error': '_LE',
            'info': '_LI',
            'warn': '_LW',
            'warning': '_LW',
            'critical': '_LC',
            'exception': '_LE',
        }
        logs = expected_marks.keys()
        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')    # 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 mark in checks._all_hints:
                stmt = "LOG.%s(%s('test'))" % (log, mark)
                self.assertEqual(
                    0 if expected_marks[log] == mark else 1,
                    len(list(checks.validate_log_translations(stmt, stmt,
                                                              'f'))))
Exemplo n.º 2
0
    def test_log_translations(self):
        expected_marks = {
            'error': '_LE',
            'info': '_LI',
            'warn': '_LW',
            'warning': '_LW',
            'critical': '_LC',
            'exception': '_LE',
        }
        logs = expected_marks.keys()
        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')    # 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 mark in checks._all_hints:
                stmt = "LOG.%s(%s('test'))" % (log, mark)
                self.assertEqual(
                    0 if expected_marks[log] == mark else 1,
                    len(list(checks.validate_log_translations(stmt, stmt,
                                                              'f'))))
Exemplo n.º 3
0
    def test_log_translations(self):
        expected_marks = {
            "error": "_LE",
            "info": "_LI",
            "warn": "_LW",
            "warning": "_LW",
            "critical": "_LC",
            "exception": "_LE",
        }
        logs = expected_marks.keys()
        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')    # 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 mark in checks._all_hints:
                stmt = "LOG.%s(%s('test'))" % (log, mark)
                self.assertEqual(
                    0 if expected_marks[log] == mark else 1,
                    len(list(checks.validate_log_translations(stmt, stmt, "f"))),
                )
Exemplo n.º 4
0
 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'))))
         filename = 'neutron/agent/f'
         bad = "LOG.%s(_('BAD - by directory'))" % log
         self.assertEqual(
             1, len(list(checks.validate_log_translations(bad,
                                                          bad,
                                                          filename))))
Exemplo n.º 5
0
 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'))))
         filename = 'neutron/agent/f'
         bad = "LOG.%s(_('BAD - by directory'))" % log
         self.assertEqual(
             1,
             len(list(checks.validate_log_translations(bad, bad,
                                                       filename))))
Exemplo n.º 6
0
 def test_log_translations(self):
     expected_marks = {
         'audit': '_',
         'error': '_LE',
         'info': '_LI',
         'warn': '_LW',
         'warning': '_LW',
         'critical': '_LC',
         'exception': '_LE',
     }
     logs = expected_marks.keys()
     levels = ['_LI', '_LW', '_LE', '_LC']
     all_marks = levels + ['_']
     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'))))
         filename = 'neutron/agent/f'
         for mark in all_marks:
             stmt = "LOG.%s(%s('test'))" % (log, mark)
             self.assertEqual(
                 0 if expected_marks[log] == mark else 1,
                 len(
                     list(
                         checks.validate_log_translations(
                             stmt, stmt, filename))))
Exemplo n.º 7
0
 def test_log_translations(self):
     expected_marks = {
         'audit': '_',
         'error': '_LE',
         'info': '_LI',
         'warn': '_LW',
         'warning': '_LW',
         'critical': '_LC',
         'exception': '_LE',
     }
     logs = expected_marks.keys()
     levels = ['_LI', '_LW', '_LE', '_LC']
     all_marks = levels + ['_']
     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'))))
         filename = 'neutron/agent/f'
         for mark in all_marks:
             stmt = "LOG.%s(%s('test'))" % (log, mark)
             self.assertEqual(
                 0 if expected_marks[log] == mark else 1,
                 len(list(checks.validate_log_translations(stmt,
                                                           stmt,
                                                           filename))))