diff options
author | Ionel Cristian Maries <contact@ionelmc.ro> | 2015-02-14 18:13:20 +0200 |
---|---|---|
committer | Ionel Cristian Maries <contact@ionelmc.ro> | 2015-02-14 18:13:20 +0200 |
commit | 26eb7f9a2e6cc6c229c6a86b6c6bb823e8f5de57 (patch) | |
tree | 4a3f9776764d7c19e21bb6bd00ca0b2164bed4d0 /pylint/test/unittest_checker_logging.py | |
parent | d5d2d14e03a22430c5feba1789fd62c8156755f2 (diff) | |
download | pylint-git-26eb7f9a2e6cc6c229c6a86b6c6bb823e8f5de57.tar.gz |
Move all package files to a pylint package.
Diffstat (limited to 'pylint/test/unittest_checker_logging.py')
-rw-r--r-- | pylint/test/unittest_checker_logging.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pylint/test/unittest_checker_logging.py b/pylint/test/unittest_checker_logging.py new file mode 100644 index 000000000..e25daac68 --- /dev/null +++ b/pylint/test/unittest_checker_logging.py @@ -0,0 +1,47 @@ +# Copyright 2014 Google Inc. All Rights Reserved. +"""Unittest for the logging checker.""" +import unittest +from astroid import test_utils + +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 = test_utils.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_callfunc(stmts[1]) + + def test_detects_renamed_standard_logging_module(self): + stmts = test_utils.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_callfunc(stmts[1]) + + @set_config(logging_modules=['logging', 'my.logging']) + def test_nonstandard_logging_module(self): + stmts = test_utils.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_callfunc(stmts[1]) + + +if __name__ == '__main__': + unittest.main() |