コード例 #1
0
ファイル: test_pragma_parser.py プロジェクト: hippo91/pylint
def test_missing_message() -> None:
    comment = "#pylint: disable = "
    match = OPTION_PO.search(comment)
    assert match
    with pytest.raises(InvalidPragmaError):
        list(parse_pragma(match.group(2)))
コード例 #2
0
    def process_tokens(self, tokens):
        """process tokens from the current module to search for module/block
        level options
        """
        control_pragmas = {"disable", "enable"}
        prev_line = None
        saw_newline = True
        seen_newline = True
        for (tok_type, content, start, _, _) in tokens:
            if prev_line and prev_line != start[0]:
                saw_newline = seen_newline
                seen_newline = False

            prev_line = start[0]
            if tok_type in (tokenize.NL, tokenize.NEWLINE):
                seen_newline = True

            if tok_type != tokenize.COMMENT:
                continue
            match = OPTION_PO.search(content)
            if match is None:
                continue

            try:
                for pragma_repr in parse_pragma(match.group(2)):
                    if pragma_repr.action in ("disable-all", "skip-file"):
                        if pragma_repr.action == "disable-all":
                            self.add_message(
                                "deprecated-pragma",
                                line=start[0],
                                args=("disable-all", "skip-file"),
                            )
                        self.add_message("file-ignored", line=start[0])
                        self._ignore_file = True
                        return
                    try:
                        meth = self._options_methods[pragma_repr.action]
                    except KeyError:
                        meth = self._bw_options_methods[pragma_repr.action]
                        # found a "(dis|en)able-msg" pragma deprecated suppression
                        self.add_message(
                            "deprecated-pragma",
                            line=start[0],
                            args=(
                                pragma_repr.action,
                                pragma_repr.action.replace("-msg", ""),
                            ),
                        )
                    for msgid in pragma_repr.messages:
                        # Add the line where a control pragma was encountered.
                        if pragma_repr.action in control_pragmas:
                            self._pragma_lineno[msgid] = start[0]

                        if (pragma_repr.action, msgid) == ("disable", "all"):
                            self.add_message(
                                "deprecated-pragma",
                                line=start[0],
                                args=("disable=all", "skip-file"),
                            )
                            self.add_message("file-ignored", line=start[0])
                            self._ignore_file = True
                            return
                            # If we did not see a newline between the previous line and now,
                            # we saw a backslash so treat the two lines as one.
                        l_start = start[0]
                        if not saw_newline:
                            l_start -= 1
                        try:
                            meth(msgid, "module", l_start)
                        except exceptions.UnknownMessageError:
                            self.add_message(
                                "bad-option-value", args=msgid, line=start[0]
                            )
            except UnRecognizedOptionError as err:
                self.add_message(
                    "unrecognized-inline-option", args=err.token, line=start[0]
                )
                continue
            except InvalidPragmaError as err:
                self.add_message("bad-inline-option", args=err.token, line=start[0])
                continue
コード例 #3
0
ファイル: test_pragma_parser.py プロジェクト: hippo91/pylint
def test_unsupported_assignment() -> None:
    comment = "#pylint: disable-all = missing-docstring"
    match = OPTION_PO.search(comment)
    assert match
    with pytest.raises(UnRecognizedOptionError):
        list(parse_pragma(match.group(2)))
コード例 #4
0
ファイル: test_pragma_parser.py プロジェクト: hippo91/pylint
def test_unknown_keyword_without_messages() -> None:
    comment = "#pylint: unknown-keyword"
    match = OPTION_PO.search(comment)
    assert match
    with pytest.raises(UnRecognizedOptionError):
        list(parse_pragma(match.group(2)))
コード例 #5
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_parse_message_with_dash():
    comment = "#pylint: disable = raw_input-builtin"
    match = OPTION_PO.search(comment)
    res = list(parse_pragma(match.group(2)))
    assert res[0].action == "disable"
    assert res[0].messages == ["raw_input-builtin"]
コード例 #6
0
ファイル: test_pragma_parser.py プロジェクト: hippo91/pylint
def test_missing_keyword() -> None:
    comment = "#pylint: = missing-docstring"
    match = OPTION_PO.search(comment)
    assert match
    with pytest.raises(InvalidPragmaError):
        list(parse_pragma(match.group(2)))
コード例 #7
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_unknown_keyword_with_messages():
    comment = "#pylint: unknown-keyword = missing-docstring"
    match = OPTION_PO.search(comment)
    with pytest.raises(UnRecognizedOptionError):
        list(parse_pragma(match.group(2)))
コード例 #8
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_missing_assignment():
    comment = "#pylint: disable missing-docstring"
    match = OPTION_PO.search(comment)
    with pytest.raises(InvalidPragmaError):
        list(parse_pragma(match.group(2)))
コード例 #9
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_simple_pragma_multiple_messages():
    comment = "#pylint: disable = missing-docstring, invalid-name"
    match = OPTION_PO.search(comment)
    for pragma_repr in parse_pragma(match.group(2)):
        assert pragma_repr.action == "disable"
        assert pragma_repr.messages == ["missing-docstring", "invalid-name"]
コード例 #10
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_simple_pragma_no_messages():
    comment = "#pylint: skip-file"
    match = OPTION_PO.search(comment)
    for pragma_repr in parse_pragma(match.group(2)):
        assert pragma_repr.action == "skip-file"
        assert pragma_repr.messages == []
コード例 #11
0
ファイル: test_pragma_parser.py プロジェクト: fjzhou/config
def test_disable_checker_with_number_in_name():
    comment = "#pylint: disable = j3-custom-checker"
    match = OPTION_PO.search(comment)
    for pragma_repr in parse_pragma(match.group(2)):
        assert pragma_repr.action == "disable"
        assert pragma_repr.messages == ["j3-custom-checker"]