mirror of
https://fuchsia.googlesource.com/third_party/github.com/pylint-dev/pylint
synced 2024-09-22 00:24:37 +00:00
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
"""Unittest for the logging checker."""
|
|
import unittest
|
|
|
|
import astroid
|
|
|
|
from pylint.checkers import logging
|
|
from pylint.testutils import CheckerTestCase, Message, set_config
|
|
|
|
|
|
class LoggingModuleDetectionTest(CheckerTestCase):
|
|
CHECKER_CLASS = logging.LoggingChecker
|
|
|
|
def test_detects_standard_logging_module(self):
|
|
stmts = astroid.extract_node("""
|
|
import logging #@
|
|
logging.warn('%s' % '%s') #@
|
|
""")
|
|
self.checker.visit_module(None)
|
|
self.checker.visit_import(stmts[0])
|
|
with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])):
|
|
self.checker.visit_call(stmts[1])
|
|
|
|
def test_detects_renamed_standard_logging_module(self):
|
|
stmts = astroid.extract_node("""
|
|
import logging as blogging #@
|
|
blogging.warn('%s' % '%s') #@
|
|
""")
|
|
self.checker.visit_module(None)
|
|
self.checker.visit_import(stmts[0])
|
|
with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])):
|
|
self.checker.visit_call(stmts[1])
|
|
|
|
@set_config(logging_modules=['logging', 'my.logging'])
|
|
def test_nonstandard_logging_module(self):
|
|
stmts = astroid.extract_node("""
|
|
from my import logging as blogging #@
|
|
blogging.warn('%s' % '%s') #@
|
|
""")
|
|
self.checker.visit_module(None)
|
|
self.checker.visit_import(stmts[0])
|
|
with self.assertAddsMessages(Message('logging-not-lazy', node=stmts[1])):
|
|
self.checker.visit_call(stmts[1])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|