aboutsummaryrefslogtreecommitdiff
path: root/tests/lint/test_utils.py
blob: f7294f353cd1ba413d28070e21bf4ca714ce08bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pathlib import Path, PosixPath

from pylint.lint.utils import get_fatal_error_message, prepare_crash_report


def test_prepare_crash_report(tmp_path: PosixPath) -> None:
    exception_content = "Exmessage"
    python_file = tmp_path / "myfile.py"
    python_content = "from shadok import MagicFaucet"
    with open(python_file, "w", encoding="utf8") as f:
        f.write(python_content)
    try:
        raise Exception(exception_content)
    except Exception as ex:  # pylint: disable=broad-except
        template_path = prepare_crash_report(
            ex, str(python_file), str(tmp_path / "pylint-crash-%Y.txt")
        )
    assert str(tmp_path) in str(template_path)
    with open(template_path, encoding="utf8") as f:
        template_content = f.read()
    assert python_content in template_content
    assert exception_content in template_content
    assert "in test_prepare_crash_report" in template_content
    assert "raise Exception(exception_content)" in template_content


def test_get_fatal_error_message() -> None:
    python_path = "mypath.py"
    crash_path = "crash.txt"
    msg = get_fatal_error_message(python_path, Path(crash_path))
    assert python_path in msg
    assert crash_path in msg
    assert "open an issue" in msg