Skip to content

Commit 5fc4efc

Browse files
Remove related tests, simplify existing one
1 parent a8a1472 commit 5fc4efc

File tree

1 file changed

+4
-51
lines changed

1 file changed

+4
-51
lines changed

tests/lint/unittest_lint.py

+4-51
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from __future__ import annotations
88

99
import argparse
10-
import datetime
1110
import os
1211
import re
1312
import sys
@@ -19,6 +18,7 @@
1918
from os.path import abspath, dirname, join, sep
2019
from pathlib import Path
2120
from shutil import copy, rmtree
21+
from unittest import mock
2222

2323
import platformdirs
2424
import pytest
@@ -31,11 +31,8 @@
3131
MSG_STATE_CONFIDENCE,
3232
MSG_STATE_SCOPE_CONFIG,
3333
MSG_STATE_SCOPE_MODULE,
34-
OLD_DEFAULT_PYLINT_HOME,
3534
PYLINT_HOME,
36-
USER_HOME,
3735
_get_pylint_home,
38-
_warn_about_old_home,
3936
)
4037
from pylint.exceptions import InvalidMessageError
4138
from pylint.lint import PyLinter, expand_modules
@@ -930,58 +927,14 @@ def pop_pylintrc() -> None:
930927

931928
@pytest.mark.usefixtures("pop_pylintrc")
932929
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")
938931
assert constants.PYLINT_HOME == expected
939932
assert PYLINT_HOME == expected
940933

941934

935+
@mock.patch.dict(os.environ, {"PYLINTHOME": "whatever.d"})
942936
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"
985938

986939

987940
class _CustomPyLinter(PyLinter):

0 commit comments

Comments
 (0)