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


Python PyLinter.check方法代码示例

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


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

示例1: run_linter

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
    def run_linter(self):
        from pylint.lint import PyLinter
        from pylint import checkers
        from os.path import join

        linter = PyLinter(pylintrc=self.lint_config)

        # same, but not all pylint versions have load_default_plugins
        if hasattr(linter, 'load_default_plugins'):
            linter.load_default_plugins()
        else:
            checkers.initialize(linter)

        linter.read_config_file()
        linter.load_config_file()

        if self.packages:
            self.announce("checking packages", 2)
            report_fn = "packages_report." + linter.reporter.extension
            report_fn = join(self.build_base, report_fn)
            with open(report_fn, "wt") as out:
                linter.reporter.set_output(out)
                linter.check(self.packages)

            self.announce_overview(linter, report_fn)

        if self.build_scripts:
            self.announce("checking scripts", 2)
            report_fn = "scripts_report." + linter.reporter.extension
            report_fn = join(self.build_base, report_fn)
            with open(report_fn, "wt") as out:
                linter.reporter.set_output(out)
                linter.check(self.build_scripts)

            self.announce_overview(linter, report_fn)
开发者ID:jenix21,项目名称:python-javatools,代码行数:37,代码来源:setup.py

示例2: process_file

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
def process_file(filename):
    """
    Analyze the file with pylint and write the result
    to a database
    """
    linter = PyLinter()

    checkers.initialize(linter)
    linter.read_config_file()
    linter.quiet = 1

    filemods = linter.expand_files((filename, ))
    if filemods:
        old_stats = config.load_results(filemods[0].get('basename'))
        old_score = old_stats.get('global_note', 0.0)

    linter.check(filename)
    score = eval(linter.config.evaluation, {}, linter.stats)

    # Calculate the credit for both scores
    if score < 0:
        credit = 2.0 * score
    elif score < old_score:
        credit = -1.5 * (old_score - score)
    elif score < MINIMUM_SCORE:
        credit = -1.5 * (MINIMUM_SCORE - score)
    else:
        credit = score - old_score

    return score, old_score, credit
开发者ID:codecollision,项目名称:DropboxToFlickr,代码行数:32,代码来源:huLint.py

示例3: check_pylint

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
    def check_pylint(self):
        """
        Check using pylint.
        """
        options = self.options.get('pylint', self.file_path).copy()
        if not options['enabled']:
            return
        del options['enabled']

        if not self._compiled_tree:
            # We failed to compile the tree.
            return

        from pylint.lint import PyLinter, fix_import_path
        from pylint.reporters import CollectingReporter

        linter = PyLinter()
        linter.load_default_plugins()
        linter.set_reporter(CollectingReporter())

        if options['py3k']:
            linter.python3_porting_mode()
        del options['py3k']

        rcfile = options.get('rcfile', None)
        del options['rcfile']

        if rcfile:
            linter.read_config_file(config_file=rcfile)
            linter.load_config_file()
        else:
            linter.load_configuration_from_config(options)

        # PyLint does its own import and parsing, so we only pass the file
        # name and the precompiled tree.
        with fix_import_path(self.file_path):
            linter.check(self.file_path)

        for message in linter.reporter.messages:
            self.message(
                message.line,
                '%s:%s %s' % (
                    message.msg_id,
                    message.symbol,
                    message.msg,
                    ),
                code=message.msg_id,
                icon='info',
                category='pylint',
                )
开发者ID:chevah,项目名称:pocket-lint,代码行数:52,代码来源:formatcheck.py

示例4: main

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
def main():
    linter = PyLinter()
    # linter.msgs = get_msg_ids(error_level)
    ns = parse_arguments()
    for mod in ns.module:
        print("module = %s" % mod)
        print(linter.check(mod))
开发者ID:AndreaCrotti,项目名称:scripts,代码行数:9,代码来源:mylint.py

示例5: main

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
def main():
    """Run the Wall code quality checks."""
    print("Running unit tests...")
    # TODO: tests = defaultTestLoader.discover('.')
    tests = defaultTestLoader.loadTestsFromNames(["wall", "wall.util", "wall.bricks.url"])
    test_result = TextTestRunner(stream=sys.stdout).run(tests)

    print("\nLinting (Python)...")
    linter = PyLinter()
    linter.load_default_plugins()
    linter.load_file_configuration()
    linter.load_configuration(ignore="lib")
    # TODO: linter.check(['wall', 'walld.py', 'sjmpc.py', 'check.py'])
    linter.check(["wall.util", "walld.py", "check.py"])

    print("\nLinting (text)...")
    checkre_result = checkre(
        {
            (
                r"(?!.*/lib/).*\.(html|css)",
                r"wall/res/default.cfg",
                r"wall/res/static/(display|remote)/config.default.json",
                r"pylintrc",
            ): (
                line_length_check(),
                simple_indentation_check(),
                trailing_space_check(),
                whitespace_check(),
                newline_at_eof_check(),
            ),
            r"(?!.*/lib/).*\.md": (
                line_length_check(),
                trailing_space_check(),
                whitespace_check(),
                newline_at_eof_check(),
            ),
            r"(?!.*/lib/|walld.py|sjmpc.py|check.py).*\.py": header_check("wall/__init__.py", 2),
            r"(?!.*/lib/).*\.js": header_check("wall/res/static/wall.js", 4),
        }
    )

    if not test_result.wasSuccessful() or linter.msg_status != 0 or checkre_result != 0:
        return 1

    print("\nEverything looks fine, good work!")
    return 0
开发者ID:NoyaInRain,项目名称:wall,代码行数:48,代码来源:check.py

示例6: run_linter

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
    def run_linter(self):
        linter = PyLinter(pylintrc=self.lint_config)

        # load_default_plugins will call checkers.initialize if
        # implemented, but some older versions of pylint don't have
        # this method so we fall back to calling is manually.
        if hasattr(linter, 'load_default_plugins'):
            linter.load_default_plugins()
        else:
            checkers.initialize(linter)

        linter.read_config_file()
        linter.load_config_file()

        # don't emit messages about suppressed or useless suppressed
        # configs, it's just annoying and doesn't help.
        #linter.disable('suppressed-message')
        #linter.disable('useless-suppression')

        if self.packages:
            self.announce("pylint is checking packages", 2)
            report_fn = "packages_report." + linter.reporter.extension
            report_fn = join(self.build_base, report_fn)
            with open(report_fn, "wt") as out:
                linter.reporter.set_output(out)
                linter.check(self.packages)

            self.announce_overview(linter, report_fn)

        if self.build_scripts:
            self.announce("pylint is checking scripts", 2)
            report_fn = "scripts_report." + linter.reporter.extension
            report_fn = join(self.build_base, report_fn)
            with open(report_fn, "wt") as out:
                linter.reporter.set_output(out)
                linter.check(self.build_scripts)

            self.announce_overview(linter, report_fn)
开发者ID:achieverForever,项目名称:python-javatools,代码行数:40,代码来源:pylint_cmd.py

示例7: Runner

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class Runner():
    """
    Run and control the checking process.
    """
    outputStream = None
    linter = None
    allowOptions = None
    # Customized checkers.
    checkers = ("header.HeaderChecker",
                "names.TwistedNamesChecker",
                "pycodestyleformat.PyCodeStyleChecker",
                "docstring.DocstringChecker",
                "formattingoperation.FormattingOperationChecker",
                "comment.CommentChecker",
                "testclassname.TestClassNameChecker")
    allowedMessagesFromPylint = ("F0001",
                                 "C0103",
                                 "C0301",
                                 "W0311",
                                 "W0312")
    diffOption = None
    errorResultRead = "Error: Failed to read result file '%s'.\n"
    prefixModuleName = "************* Module "
    regexLineStart = "^[WCEFR]\d{4}\:"

    def __init__(self):
        """
        Initialize C{PyLinter} object, and load configuration file.
        """
        self.allowOptions = True
        self.linter = PyLinter(self._makeOptions())
        # register standard checkers.
        self.linter.load_default_plugins()
        # read configuration.
        pathConfig = os.path.join(twistedchecker.abspath,
                                  "configuration", "pylintrc")
        self.linter.read_config_file(pathConfig)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered.
        self.linter.load_config_file()
        allowedMessages = self.registerCheckers()
        # disable messages
        disabledMessages = set(self.linter
                           .cfgfile_parser.get("TWISTEDCHECKER", "disable")
                           .replace(" ", "").split(","))
        if disabledMessages != {""}:
            for msg in disabledMessages:
                self.linter.disable(msg)
            allowedMessages -= disabledMessages
        # set default output stream to stdout
        self.setOutput(sys.stdout)
        # set default reporter to limited reporter
        self.setReporter(LimitedReporter(allowedMessages))


    def _makeOptions(self):
        """
        Return options for twistedchecker.
        """
        return (
            ("diff",
             {"type": "string",
              "metavar": "<result-file>",
              "help": "Set comparing result file to automatically "
                      "generate a diff."}
            ),
            ('pep8',
             {'type': 'yn', 'metavar': '<y_or_n>',
              'default': False,
              'help': 'Show pep8 warnings.'}
            ),
            ('strict-epydoc',
             {'type': 'yn', 'metavar': '<y_or_n>',
              'default': False,
              'help': "Check '@type' and '@rtype' in epydoc."}
            ),
          )


    def setOutput(self, stream):
        """
        Set the stream to output result of checking.

        @param stream: output stream, defaultly it should be stdout
        """
        self.outputStream = stream
        sys.stdout = stream


    def setReporter(self, reporter):
        """
        Set the reporter of pylint.

        @param reporter: reporter used to show messages
        """
        self.linter.set_reporter(reporter)


    def displayHelp(self):
        """
#.........这里部分代码省略.........
开发者ID:twisted,项目名称:twistedchecker,代码行数:103,代码来源:runner.py

示例8: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(TestCase):

    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable('I')
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)

    def test_message_help(self):
        msg = self.linter.get_message_help('F0001', checkerref=True)
        expected = ':F0001:\n  Used when an error occurred preventing the analysis of a module (unable to\n  find it for instance). This message belongs to the master checker.'
        self.assertMultiLineEqual(msg, expected)
        self.assertRaises(UnknownMessage, self.linter.get_message_help, 'YB12')

    def test_enable_message(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102'))
        linter.disable('W0101', scope='package')
        linter.disable('W0102', scope='module', line=1)
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(not linter.is_message_enabled('W0102', 1))
        linter.set_current_module('tutu')
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102'))
        linter.enable('W0101', scope='package')
        linter.enable('W0102', scope='module', line=1)
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102', 1))

    def test_enable_message_category(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        linter.disable('W', scope='package')
        linter.disable('C', scope='module', line=1)
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        self.assert_(not linter.is_message_enabled('C0121', line=1))
        linter.set_current_module('tutu')
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        linter.enable('W', scope='package')
        linter.enable('C', scope='module', line=1)
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        self.assert_(linter.is_message_enabled('C0121', line=1))

    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')
        astng = linter.get_astng(filepath, 'func_block_disable_msg')
        linter.process_module(astng)
        orig_state = linter._module_msgs_state.copy()
        linter._module_msgs_state = {}
        linter.collect_block_lines(astng, 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):
#.........这里部分代码省略.........
开发者ID:michellesun,项目名称:hunt-for-ciabatta,代码行数:103,代码来源:unittest_lint.py

示例9: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(TestCase):

    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable('I')
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)
        self.linter.set_reporter(TestReporter())

    def init_linter(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        linter.file_state = FileState('toto')
        return linter

    def test_enable_message(self):
        linter = self.init_linter()
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.disable('W0101', scope='package')
        linter.disable('W0102', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertFalse(linter.is_message_enabled('W0102', 1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.enable('W0101', scope='package')
        linter.enable('W0102', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102', 1))

    def test_enable_message_category(self):
        linter = self.init_linter()
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.disable('W', scope='package')
        linter.disable('C', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertFalse(linter.is_message_enabled('C0121', line=1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.enable('W', scope='package')
        linter.enable('C', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertTrue(linter.is_message_enabled('C0121', line=1))

    def test_message_state_scope(self):
        linter = self.init_linter()
        fs = linter.file_state
        linter.disable('C0121')
        self.assertEqual(MSG_STATE_SCOPE_CONFIG,
                         fs._message_state_scope('C0121'))
        linter.disable('W0101', scope='module', line=3)
        self.assertEqual(MSG_STATE_SCOPE_CONFIG,
                         fs._message_state_scope('C0121'))
        self.assertEqual(MSG_STATE_SCOPE_MODULE,
                         fs._message_state_scope('W0101', 3))
        linter.enable('W0102', scope='module', line=3)
        self.assertEqual(MSG_STATE_SCOPE_MODULE,
                         fs._message_state_scope('W0102', 3))

    def test_enable_message_block(self):
        linter = self.init_linter()
        linter.open()
        filepath = join(INPUTDIR, 'func_block_disable_msg.py')
        linter.set_current_module('func_block_disable_msg')
        astroid = linter.get_ast(filepath, 'func_block_disable_msg')
        linter.process_tokens(tokenize_module(astroid))
        fs = linter.file_state
        fs.collect_block_lines(linter.msgs_store, astroid)
        # global (module level)
        self.assertTrue(linter.is_message_enabled('W0613'))
        self.assertTrue(linter.is_message_enabled('E1101'))
        # meth1
        self.assertTrue(linter.is_message_enabled('W0613', 13))
        # meth2
        self.assertFalse(linter.is_message_enabled('W0613', 18))
        # meth3
        self.assertFalse(linter.is_message_enabled('E1101', 24))
        self.assertTrue(linter.is_message_enabled('E1101', 26))
        # meth4
        self.assertFalse(linter.is_message_enabled('E1101', 32))
        self.assertTrue(linter.is_message_enabled('E1101', 36))
        # meth5
        self.assertFalse(linter.is_message_enabled('E1101', 42))
        self.assertFalse(linter.is_message_enabled('E1101', 43))
        self.assertTrue(linter.is_message_enabled('E1101', 46))
        self.assertFalse(linter.is_message_enabled('E1101', 49))
        self.assertFalse(linter.is_message_enabled('E1101', 51))
        # meth6
        self.assertFalse(linter.is_message_enabled('E1101', 57))
        self.assertTrue(linter.is_message_enabled('E1101', 61))
        self.assertFalse(linter.is_message_enabled('E1101', 64))
        self.assertFalse(linter.is_message_enabled('E1101', 66))

#.........这里部分代码省略.........
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:103,代码来源:unittest_lint.py

示例10: PyLinter

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
#!/usr/bin/env python

from cStringIO import StringIO
from pylint.lint import PyLinter
from pylint.reporters.text import ParseableTextReporter

l = PyLinter()


reporter = ParseableTextReporter()
result = StringIO()
reporter.set_output(result)
l.check(__file__)
开发者ID:kilirobbs,项目名称:python-fiddle,代码行数:15,代码来源:__dict__.py

示例11: PyLinter

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
#!/usr/bin/env python
from pylint.lint import PyLinter
from pylint import checkers

linter = PyLinter()

checkers.initialize(linter)
linter.quiet = 999
linter.check("errors.py")
s=linter.stats
开发者ID:kilirobbs,项目名称:python-fiddle,代码行数:12,代码来源:test.py

示例12: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(TestCase):

    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable('I')
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)

    def test_message_help(self):
        msg = self.linter.get_message_help('F0001', checkerref=True)
        expected = ':F0001:\n  Used when an error occurred preventing the analysis of a module (unable to\n  find it for instance). This message belongs to the master checker.'
        self.assertTextEqual(msg, expected)
        self.assertRaises(UnknownMessage, self.linter.get_message_help, 'YB12')

    def test_enable_message(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102'))
        linter.disable('W0101', scope='package')
        linter.disable('W0102', scope='module', line=1)
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(not linter.is_message_enabled('W0102', 1))
        linter.set_current_module('tutu')
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102'))
        linter.enable('W0101', scope='package')
        linter.enable('W0102', scope='module', line=1)
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('W0102', 1))

    def test_enable_message_category(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        linter.disable('W', scope='package')
        linter.disable('C', scope='module', line=1)
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        self.assert_(not linter.is_message_enabled('C0121', line=1))
        linter.set_current_module('tutu')
        self.assert_(not linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        linter.enable('W', scope='package')
        linter.enable('C', scope='module', line=1)
        self.assert_(linter.is_message_enabled('W0101'))
        self.assert_(linter.is_message_enabled('C0121'))
        self.assert_(linter.is_message_enabled('C0121', line=1))

    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()
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例13: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(unittest.TestCase):
    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable("I")
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)
        self.linter.set_reporter(TestReporter())

    def init_linter(self):
        linter = self.linter
        linter.open()
        linter.set_current_module("toto")
        linter.file_state = FileState("toto")
        return linter

    def test_enable_message(self):
        linter = self.init_linter()
        self.assertTrue(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("W0102"))
        linter.disable("W0101", scope="package")
        linter.disable("W0102", scope="module", line=1)
        self.assertFalse(linter.is_message_enabled("W0101"))
        self.assertFalse(linter.is_message_enabled("W0102", 1))
        linter.set_current_module("tutu")
        self.assertFalse(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("W0102"))
        linter.enable("W0101", scope="package")
        linter.enable("W0102", scope="module", line=1)
        self.assertTrue(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("W0102", 1))

    def test_enable_message_category(self):
        linter = self.init_linter()
        self.assertTrue(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("C0121"))
        linter.disable("W", scope="package")
        linter.disable("C", scope="module", line=1)
        self.assertFalse(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("C0121"))
        self.assertFalse(linter.is_message_enabled("C0121", line=1))
        linter.set_current_module("tutu")
        self.assertFalse(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("C0121"))
        linter.enable("W", scope="package")
        linter.enable("C", scope="module", line=1)
        self.assertTrue(linter.is_message_enabled("W0101"))
        self.assertTrue(linter.is_message_enabled("C0121"))
        self.assertTrue(linter.is_message_enabled("C0121", line=1))

    def test_message_state_scope(self):
        class FakeConfig(object):
            confidence = ["HIGH"]

        linter = self.init_linter()
        linter.disable("C0121")
        self.assertEqual(MSG_STATE_SCOPE_CONFIG, linter.get_message_state_scope("C0121"))
        linter.disable("W0101", scope="module", line=3)
        self.assertEqual(MSG_STATE_SCOPE_CONFIG, linter.get_message_state_scope("C0121"))
        self.assertEqual(MSG_STATE_SCOPE_MODULE, linter.get_message_state_scope("W0101", 3))
        linter.enable("W0102", scope="module", line=3)
        self.assertEqual(MSG_STATE_SCOPE_MODULE, linter.get_message_state_scope("W0102", 3))
        linter.config = FakeConfig()
        self.assertEqual(
            MSG_STATE_CONFIDENCE, linter.get_message_state_scope("this-is-bad", confidence=interfaces.INFERENCE)
        )

    def test_enable_message_block(self):
        linter = self.init_linter()
        linter.open()
        filepath = join(INPUTDIR, "func_block_disable_msg.py")
        linter.set_current_module("func_block_disable_msg")
        astroid = linter.get_ast(filepath, "func_block_disable_msg")
        linter.process_tokens(tokenize_module(astroid))
        fs = linter.file_state
        fs.collect_block_lines(linter.msgs_store, astroid)
        # global (module level)
        self.assertTrue(linter.is_message_enabled("W0613"))
        self.assertTrue(linter.is_message_enabled("E1101"))
        # meth1
        self.assertTrue(linter.is_message_enabled("W0613", 13))
        # meth2
        self.assertFalse(linter.is_message_enabled("W0613", 18))
        # meth3
        self.assertFalse(linter.is_message_enabled("E1101", 24))
        self.assertTrue(linter.is_message_enabled("E1101", 26))
        # meth4
        self.assertFalse(linter.is_message_enabled("E1101", 32))
        self.assertTrue(linter.is_message_enabled("E1101", 36))
        # meth5
        self.assertFalse(linter.is_message_enabled("E1101", 42))
        self.assertFalse(linter.is_message_enabled("E1101", 43))
        self.assertTrue(linter.is_message_enabled("E1101", 46))
        self.assertFalse(linter.is_message_enabled("E1101", 49))
        self.assertFalse(linter.is_message_enabled("E1101", 51))
        # meth6
        self.assertFalse(linter.is_message_enabled("E1101", 57))
        self.assertTrue(linter.is_message_enabled("E1101", 61))
        self.assertFalse(linter.is_message_enabled("E1101", 64))
        self.assertFalse(linter.is_message_enabled("E1101", 66))
#.........这里部分代码省略.........
开发者ID:si618,项目名称:pi-time,代码行数:103,代码来源:unittest_lint.py

示例14: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(TestCase):

    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable('I')
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)
        self.linter.set_reporter(TestReporter())

    def _compare_messages(self, desc, msg, checkerref=False):
        # replace \r\n with \n, because
        # logilab.common.textutils.normalize_text
        # uses os.linesep, which will
        # not properly compare with triple
        # quoted multilines used in these tests 
        self.assertMultiLineEqual(desc,
             msg.format_help(checkerref=checkerref)
                .replace('\r\n', '\n'))

    def test_check_message_id(self):
        self.assertIsInstance(self.linter.check_message_id('F0001'),
                              MessageDefinition)
        self.assertRaises(UnknownMessage,
                          self.linter.check_message_id, 'YB12')

    def test_message_help(self):
        msg = self.linter.check_message_id('F0001')
        self._compare_messages(
            ''':fatal (F0001):
  Used when an error occurred preventing the analysis of a module (unable to
  find it for instance). This message belongs to the master checker.''',
            msg, checkerref=True)
        self._compare_messages(
            ''':fatal (F0001):
  Used when an error occurred preventing the analysis of a module (unable to
  find it for instance).''',
            msg, checkerref=False)

    def test_message_help_minmax(self):
        # build the message manually to be python version independant
        msg = build_message_def(self.linter._checkers['typecheck'][0],
                                'E1122', checkers.typecheck.MSGS['E1122'])
        self._compare_messages(
            ''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in function call*
  Used when a function call passes the same keyword argument multiple times.
  This message belongs to the typecheck checker. It can't be emitted when using
  Python >= 2.6.''',
            msg, checkerref=True)
        self._compare_messages(
            ''':duplicate-keyword-arg (E1122): *Duplicate keyword argument %r in function call*
  Used when a function call passes the same keyword argument multiple times.
  This message can't be emitted when using Python >= 2.6.''',
            msg, checkerref=False)

    def test_enable_message(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.disable('W0101', scope='package')
        linter.disable('W0102', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertFalse(linter.is_message_enabled('W0102', 1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.enable('W0101', scope='package')
        linter.enable('W0102', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102', 1))

    def test_enable_message_category(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.disable('W', scope='package')
        linter.disable('C', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertFalse(linter.is_message_enabled('C0121', line=1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.enable('W', scope='package')
        linter.enable('C', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertTrue(linter.is_message_enabled('C0121', line=1))

    def test_message_state_scope(self):
        linter = self.linter
        linter.open()
        linter.disable('C0121')
        self.assertEqual(MSG_STATE_SCOPE_CONFIG,
                         linter.get_message_state_scope('C0121'))
        linter.disable('W0101', scope='module', line=3)
#.........这里部分代码省略.........
开发者ID:Launcelot,项目名称:nupic-linux64,代码行数:103,代码来源:unittest_lint.py

示例15: PyLinterTC

# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import check [as 别名]
class PyLinterTC(TestCase):

    def setUp(self):
        self.linter = PyLinter()
        self.linter.disable('I')
        self.linter.config.persistent = 0
        # register checkers
        checkers.initialize(self.linter)
        self.linter.set_reporter(TestReporter())

    def test_message_help(self):
        msg = self.linter.get_message_help('F0001', checkerref=True)
        expected = ':F0001 (fatal):\n  Used when an error occurred preventing the analysis of a module (unable to\n  find it for instance). This message belongs to the master checker.'
        self.assertMultiLineEqual(msg, expected)
        self.assertRaises(UnknownMessage, self.linter.get_message_help, 'YB12')

    def test_enable_message(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.disable('W0101', scope='package')
        linter.disable('W0102', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertFalse(linter.is_message_enabled('W0102', 1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102'))
        linter.enable('W0101', scope='package')
        linter.enable('W0102', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('W0102', 1))

    def test_enable_message_category(self):
        linter = self.linter
        linter.open()
        linter.set_current_module('toto')
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.disable('W', scope='package')
        linter.disable('C', scope='module', line=1)
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertFalse(linter.is_message_enabled('C0121', line=1))
        linter.set_current_module('tutu')
        self.assertFalse(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        linter.enable('W', scope='package')
        linter.enable('C', scope='module', line=1)
        self.assertTrue(linter.is_message_enabled('W0101'))
        self.assertTrue(linter.is_message_enabled('C0121'))
        self.assertTrue(linter.is_message_enabled('C0121', line=1))

    def test_message_state_scope(self):
        linter = self.linter
        linter.open()
        linter.disable('C0121')
        self.assertEqual(MSG_STATE_SCOPE_CONFIG,
                         linter.get_message_state_scope('C0121'))
        linter.disable('W0101', scope='module', line=3)
        self.assertEqual(MSG_STATE_SCOPE_CONFIG,
                         linter.get_message_state_scope('C0121'))
        self.assertEqual(MSG_STATE_SCOPE_MODULE,
                         linter.get_message_state_scope('W0101', 3))
        linter.enable('W0102', scope='module', line=3)
        self.assertEqual(MSG_STATE_SCOPE_MODULE,
                         linter.get_message_state_scope('W0102', 3))

    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')
        astroid = linter.get_astroid(filepath, 'func_block_disable_msg')
        linter.process_tokens(tokenize_module(astroid))
        orig_state = linter._module_msgs_state.copy()
        linter._module_msgs_state = {}
        linter._suppression_mapping = {}
        linter.collect_block_lines(astroid, orig_state)
        # global (module level)
        self.assertTrue(linter.is_message_enabled('W0613'))
        self.assertTrue(linter.is_message_enabled('E1101'))
        # meth1
        self.assertTrue(linter.is_message_enabled('W0613', 13))
        # meth2
        self.assertFalse(linter.is_message_enabled('W0613', 18))
        # meth3
        self.assertFalse(linter.is_message_enabled('E1101', 24))
        self.assertTrue(linter.is_message_enabled('E1101', 26))
        # meth4
        self.assertFalse(linter.is_message_enabled('E1101', 32))
        self.assertTrue(linter.is_message_enabled('E1101', 36))
        # meth5
        self.assertFalse(linter.is_message_enabled('E1101', 42))
        self.assertFalse(linter.is_message_enabled('E1101', 43))
        self.assertTrue(linter.is_message_enabled('E1101', 46))
        self.assertFalse(linter.is_message_enabled('E1101', 49))
        self.assertFalse(linter.is_message_enabled('E1101', 51))
        # meth6
#.........这里部分代码省略.........
开发者ID:aras0,项目名称:porownywarka-ofert,代码行数:103,代码来源:unittest_lint.py


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