Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a regression tests for https://github.com/PyCQA/astroid/pull/1207 #5210

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tests/lint/test_pylinter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Any, NoReturn
from unittest.mock import patch

from astroid import AstroidBuildingError
from astroid import AstroidBuildingError, extract_node, nodes
from py._path.local import LocalPath # type: ignore[import]
from pytest import CaptureFixture

from pylint.checkers.utils import safe_infer
from pylint.lint.pylinter import PyLinter
from pylint.utils import FileState

Expand All @@ -13,6 +14,20 @@ def raise_exception(*args: Any, **kwargs: Any) -> NoReturn:
raise AstroidBuildingError(modname="spam")


def test_safe_infer_on_bz2_compress_return():
"""Regression tests for https://github.com/PyCQA/astroid/pull/1207"""
src_node = extract_node('import bz2\nunused = bz2.compress(b"")')
assignment = next(src_node.nodes_of_class(nodes.Assign))
inferred = safe_infer(assignment.value.func)
assert isinstance(inferred, nodes.FunctionDef), str(inferred)
try:
value = next(inferred.nodes_of_class(nodes.Return))
assert isinstance(value, nodes.Return)
assert value.parent.name == "compress"
except StopIteration:
assert False, f"No return found in body of:\n{str(inferred)}."


@patch.object(FileState, "iter_spurious_suppression_messages", raise_exception)
def test_crash_in_file(
linter: PyLinter, capsys: CaptureFixture, tmpdir: LocalPath
Expand Down