|
7 | 7 | from __future__ import annotations
|
8 | 8 |
|
9 | 9 | import argparse
|
10 |
| -import datetime |
11 | 10 | import os
|
12 | 11 | import re
|
13 | 12 | import sys
|
|
19 | 18 | from os.path import abspath, dirname, join, sep
|
20 | 19 | from pathlib import Path
|
21 | 20 | from shutil import copy, rmtree
|
| 21 | +from unittest import mock |
22 | 22 |
|
23 | 23 | import platformdirs
|
24 | 24 | import pytest
|
|
31 | 31 | MSG_STATE_CONFIDENCE,
|
32 | 32 | MSG_STATE_SCOPE_CONFIG,
|
33 | 33 | MSG_STATE_SCOPE_MODULE,
|
34 |
| - OLD_DEFAULT_PYLINT_HOME, |
35 | 34 | PYLINT_HOME,
|
36 |
| - USER_HOME, |
37 | 35 | _get_pylint_home,
|
38 |
| - _warn_about_old_home, |
39 | 36 | )
|
40 | 37 | from pylint.exceptions import InvalidMessageError
|
41 | 38 | from pylint.lint import PyLinter, expand_modules
|
@@ -930,58 +927,14 @@ def pop_pylintrc() -> None:
|
930 | 927 |
|
931 | 928 | @pytest.mark.usefixtures("pop_pylintrc")
|
932 | 929 | def test_pylint_home() -> None:
|
933 |
| - uhome = os.path.expanduser("~") |
934 |
| - if uhome == "~": |
935 |
| - expected = OLD_DEFAULT_PYLINT_HOME |
936 |
| - else: |
937 |
| - expected = platformdirs.user_cache_dir("pylint") |
| 930 | + expected = platformdirs.user_cache_dir("pylint") |
938 | 931 | assert constants.PYLINT_HOME == expected
|
939 | 932 | assert PYLINT_HOME == expected
|
940 | 933 |
|
941 | 934 |
|
| 935 | +@mock.patch.dict(os.environ, {"PYLINTHOME": "whatever.d"}) |
942 | 936 | def test_pylint_home_from_environ() -> None:
|
943 |
| - try: |
944 |
| - pylintd = join(tempfile.gettempdir(), OLD_DEFAULT_PYLINT_HOME) |
945 |
| - os.environ["PYLINTHOME"] = pylintd |
946 |
| - try: |
947 |
| - assert _get_pylint_home() == pylintd |
948 |
| - finally: |
949 |
| - try: |
950 |
| - rmtree(pylintd) |
951 |
| - except FileNotFoundError: |
952 |
| - pass |
953 |
| - finally: |
954 |
| - del os.environ["PYLINTHOME"] |
955 |
| - |
956 |
| - |
957 |
| -def test_warn_about_old_home(capsys: CaptureFixture[str]) -> None: |
958 |
| - """Test that we correctly warn about old_home.""" |
959 |
| - # Create old home |
960 |
| - old_home = Path(USER_HOME) / OLD_DEFAULT_PYLINT_HOME |
961 |
| - old_home.mkdir(parents=True, exist_ok=True) |
962 |
| - |
963 |
| - # Create spam prevention file |
964 |
| - ten_years_ago = datetime.datetime.now() - datetime.timedelta(weeks=520) |
965 |
| - new_prevention_file = Path(PYLINT_HOME) / ten_years_ago.strftime( |
966 |
| - "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" |
967 |
| - ) |
968 |
| - with open(new_prevention_file, "w", encoding="utf8") as f: |
969 |
| - f.write("") |
970 |
| - |
971 |
| - # Remove current prevention file |
972 |
| - cur_prevention_file = Path(PYLINT_HOME) / datetime.datetime.now().strftime( |
973 |
| - "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" |
974 |
| - ) |
975 |
| - if cur_prevention_file.exists(): |
976 |
| - os.remove(cur_prevention_file) |
977 |
| - |
978 |
| - _warn_about_old_home(Path(PYLINT_HOME)) |
979 |
| - |
980 |
| - assert not new_prevention_file.exists() |
981 |
| - assert cur_prevention_file.exists() |
982 |
| - |
983 |
| - out = capsys.readouterr() |
984 |
| - assert "PYLINTHOME is now" in out.err |
| 937 | + assert _get_pylint_home() == "whatever.d" |
985 | 938 |
|
986 | 939 |
|
987 | 940 | class _CustomPyLinter(PyLinter):
|
|
0 commit comments