当前位置: 首页>>代码示例>>Python>>正文


Python PyLinter.enable_checkers方法代码示例

本文整理汇总了Python中pylint.lint.PyLinter.enable_checkers方法的典型用法代码示例。如果您正苦于以下问题:Python PyLinter.enable_checkers方法的具体用法?Python PyLinter.enable_checkers怎么用?Python PyLinter.enable_checkers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pylint.lint.PyLinter的用法示例。


在下文中一共展示了PyLinter.enable_checkers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import enable_checkers [as 别名]

#.........这里部分代码省略.........
        # meth2
        self.assert_(not linter.is_message_enabled("W0613", 18))
        # meth3
        self.assert_(not linter.is_message_enabled("E1101", 24))
        self.assert_(linter.is_message_enabled("E1101", 26))
        # meth4
        self.assert_(not linter.is_message_enabled("E1101", 32))
        self.assert_(linter.is_message_enabled("E1101", 36))
        # meth5
        self.assert_(not linter.is_message_enabled("E1101", 42))
        self.assert_(not linter.is_message_enabled("E1101", 43))
        self.assert_(linter.is_message_enabled("E1101", 46))
        self.assert_(not linter.is_message_enabled("E1101", 49))
        self.assert_(not linter.is_message_enabled("E1101", 51))
        # meth6
        self.assert_(not linter.is_message_enabled("E1101", 57))
        self.assert_(linter.is_message_enabled("E1101", 61))
        self.assert_(not linter.is_message_enabled("E1101", 64))
        self.assert_(not linter.is_message_enabled("E1101", 66))

        self.assert_(linter.is_message_enabled("E0602", 57))
        self.assert_(linter.is_message_enabled("E0602", 61))
        self.assert_(not linter.is_message_enabled("E0602", 62))
        self.assert_(linter.is_message_enabled("E0602", 64))
        self.assert_(linter.is_message_enabled("E0602", 66))
        # meth7
        self.assert_(not linter.is_message_enabled("E1101", 70))
        self.assert_(linter.is_message_enabled("E1101", 72))
        self.assert_(linter.is_message_enabled("E1101", 75))
        self.assert_(linter.is_message_enabled("E1101", 77))

    def test_list_messages(self):
        sys.stdout = StringIO()
        try:
            # just invoke it, don't check the output
            self.linter.list_messages()
        finally:
            sys.stdout = sys.__stdout__

    def test_lint_ext_module_with_file_output(self):
        self.linter.config.files_output = True
        try:
            self.linter.check("StringIO")
            self.assert_(os.path.exists("pylint_StringIO.txt"))
            self.assert_(os.path.exists("pylint_global.txt"))
        finally:
            try:
                os.remove("pylint_StringIO.txt")
                os.remove("pylint_global.txt")
            except:
                pass

    def test_enable_report(self):
        self.assertEquals(self.linter.is_report_enabled("R0001"), True)
        self.linter.disable_report("R0001")
        self.assertEquals(self.linter.is_report_enabled("R0001"), False)
        self.linter.enable_report("R0001")
        self.assertEquals(self.linter.is_report_enabled("R0001"), True)

    def test_set_option_1(self):
        linter = self.linter
        linter.set_option("disable-msg", "C0111,W0142")
        self.assert_(not linter.is_message_enabled("C0111"))
        self.assert_(not linter.is_message_enabled("W0142"))
        self.assert_(linter.is_message_enabled("W0113"))

    def test_set_option_2(self):
        linter = self.linter
        linter.set_option("disable-msg", ("C0111", "W0142"))
        self.assert_(not linter.is_message_enabled("C0111"))
        self.assert_(not linter.is_message_enabled("W0142"))
        self.assert_(linter.is_message_enabled("W0113"))

    def test_enable_checkers1(self):
        self.linter.enable_checkers(["design"], False)
        self.assertEquals(
            sorted([c.name for c in self.linter._checkers.values() if c.is_enabled()]),
            [
                "basic",
                "classes",
                "exceptions",
                "format",
                "imports",
                "logging",
                "master",
                "metrics",
                "miscellaneous",
                "newstyle",
                "similarities",
                "string_format",
                "typecheck",
                "variables",
            ],
        )

    def test_enable_checkers2(self):
        self.linter.enable_checkers(["design"], True)
        self.assertEquals(
            sorted([c.name for c in self.linter._checkers.values() if c.is_enabled()]), ["design", "master"]
        )
开发者ID:,项目名称:,代码行数:104,代码来源:

示例2: TestReporter

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import enable_checkers [as 别名]
from os import linesep
from os.path import exists

from logilab.common import testlib

from utils import get_tests_info, fix_path, TestReporter

from pylint.lint import PyLinter
from pylint import checkers

test_reporter = TestReporter()
linter = PyLinter()
linter.set_reporter(test_reporter)
linter.config.persistent = 0
checkers.initialize(linter)
linter.enable_checkers(['rpython'], True)
                       
from test_func import ulines, LintTestUsingFile

class RLintTestUsingFile(LintTestUsingFile):            
    package = 'rpythoninput'
    linter = linter
    def setUp(self):
        if sys.version_info[:2] != (2, 4):
            self.skip('only python 2.4 supported for now')
            
    def test_functionality(self):
        tocheck = ['rpythoninput/' + self.module + '.py']
        if self.depends:
            tocheck += ['rpythoninput/%s' % name for name, file in self.depends]
        self._test(tocheck)
开发者ID:bmcharek,项目名称:opendata101-workshops,代码行数:33,代码来源:test_func_rpython.py

示例3: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import enable_checkers [as 别名]

#.........这里部分代码省略.........
    def test_enable_message_block(self):
        linter = self.linter
        linter.open()
        filepath = join(INPUTDIR, 'func_block_disable_msg.py')
        linter.set_current_module('func_block_disable_msg')
        linter.process_module(open(filepath))
        orig_state = linter._module_msgs_state.copy()
        linter._module_msgs_state = {}
        linter.collect_block_lines(linter.get_astng(filepath, 'func_block_disable_msg'), orig_state)
        # global (module level)
        self.assert_(linter.is_message_enabled('W0613'))
        self.assert_(linter.is_message_enabled('E1101'))
        # meth1
        self.assert_(linter.is_message_enabled('W0613', 13))
        # meth2
        self.assert_(not linter.is_message_enabled('W0613', 18))
        # meth3
        self.assert_(not linter.is_message_enabled('E1101', 24))
        self.assert_(linter.is_message_enabled('E1101', 26))
        # meth4        
        self.assert_(not linter.is_message_enabled('E1101', 32))
        self.assert_(linter.is_message_enabled('E1101', 36))
        # meth5
        self.assert_(not linter.is_message_enabled('E1101', 42))
        self.assert_(not linter.is_message_enabled('E1101', 43))
        self.assert_(linter.is_message_enabled('E1101', 46))
        self.assert_(not linter.is_message_enabled('E1101', 49))
        self.assert_(not linter.is_message_enabled('E1101', 51))
        # meth6
        self.assert_(not linter.is_message_enabled('E1101', 57))
        self.assert_(linter.is_message_enabled('E1101', 61))
        self.assert_(not linter.is_message_enabled('E1101', 64))
        self.assert_(not linter.is_message_enabled('E1101', 66))
        
        self.assert_(linter.is_message_enabled('E0602', 57))
        self.assert_(linter.is_message_enabled('E0602', 61))
        self.assert_(not linter.is_message_enabled('E0602', 62))
        self.assert_(linter.is_message_enabled('E0602', 64))
        self.assert_(linter.is_message_enabled('E0602', 66))
        # meth7
        self.assert_(not linter.is_message_enabled('E1101', 70))
        self.assert_(linter.is_message_enabled('E1101', 72))
        self.assert_(linter.is_message_enabled('E1101', 75))
        self.assert_(linter.is_message_enabled('E1101', 77))
        
    def test_list_messages(self):
        sys.stdout = StringIO()
        try:
            # just invoke it, don't check the output
            self.linter.list_messages()
        finally:
            sys.stdout = sys.__stdout__

    def test_lint_ext_module_with_file_output(self):
        self.linter.config.files_output = True
        try:
            self.linter.check('StringIO')
            self.assert_(os.path.exists('pylint_StringIO.txt'))
            self.assert_(os.path.exists('pylint_global.txt'))
        finally:
            try:
                os.remove('pylint_StringIO.txt')
                os.remove('pylint_global.txt')
            except:
                pass

    def test_enable_report(self):
        self.assertEquals(self.linter.is_report_enabled('R0001'), True)
        self.linter.disable_report('R0001')
        self.assertEquals(self.linter.is_report_enabled('R0001'), False)
        self.linter.enable_report('R0001')
        self.assertEquals(self.linter.is_report_enabled('R0001'), True)

    def test_set_option_1(self):
        linter = self.linter
        linter.set_option('disable-msg', 'C0111,W0142')
        self.assert_(not linter.is_message_enabled('C0111'))
        self.assert_(not linter.is_message_enabled('W0142'))
        self.assert_(linter.is_message_enabled('W0113'))

    def test_set_option_2(self):
        linter = self.linter
        linter.set_option('disable-msg', ('C0111', 'W0142') )
        self.assert_(not linter.is_message_enabled('C0111'))
        self.assert_(not linter.is_message_enabled('W0142'))
        self.assert_(linter.is_message_enabled('W0113'))

    def test_enable_checkers1(self):
        self.linter.enable_checkers(['design'], False)
        self.assertEquals(sorted([c.name for c in self.linter._checkers.values()
                                  if c.is_enabled()]),
                          ['basic', 'classes', 'exceptions', 'format', 'imports',
                           'master', 'metrics', 'miscellaneous', 'newstyle',
                           'similarities', 'typecheck', 'variables'])
        
    def test_enable_checkers2(self):
        self.linter.enable_checkers(['design'], True)
        self.assertEquals(sorted([c.name for c in self.linter._checkers.values()
                           if c.is_enabled()]),
                          ['design', 'master'])
开发者ID:bmcharek,项目名称:opendata101-workshops,代码行数:104,代码来源:unittest_lint.py


注:本文中的pylint.lint.PyLinter.enable_checkers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。