diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-05-05 17:22:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 17:22:22 +0200 |
commit | 04d54f3d179d378076e9dd465cbd8a35a32d659b (patch) | |
tree | 169ba2f42c81a4524e507a8c489dd6790cece84c /tests/lint | |
parent | 12648fde32b7ed976666e5ff5b35171c0bd50150 (diff) | |
download | pylint-git-04d54f3d179d378076e9dd465cbd8a35a32d659b.tar.gz |
Move ``PYLINTHOME`` to constants and test it (#6509)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/lint')
-rw-r--r-- | tests/lint/unittest_lint.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 78b89974c..37c912c7b 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -7,6 +7,7 @@ from __future__ import annotations import argparse +import datetime import os import re import sys @@ -17,6 +18,7 @@ from importlib import reload from io import StringIO from os import chdir, getcwd from os.path import abspath, dirname, join, sep +from pathlib import Path from shutil import rmtree import platformdirs @@ -30,6 +32,10 @@ from pylint.constants import ( MSG_STATE_SCOPE_CONFIG, MSG_STATE_SCOPE_MODULE, OLD_DEFAULT_PYLINT_HOME, + PYLINT_HOME, + USER_HOME, + _get_pylint_home, + _warn_about_old_home, ) from pylint.exceptions import InvalidMessageError from pylint.lint import PyLinter @@ -637,13 +643,15 @@ def test_pylint_home() -> None: else: expected = platformdirs.user_cache_dir("pylint") assert config.PYLINT_HOME == expected + assert PYLINT_HOME == expected + +def test_pylint_home_from_environ() -> None: try: pylintd = join(tempfile.gettempdir(), OLD_DEFAULT_PYLINT_HOME) os.environ["PYLINTHOME"] = pylintd try: - reload(config) - assert config.PYLINT_HOME == pylintd + assert _get_pylint_home() == pylintd finally: try: rmtree(pylintd) @@ -653,6 +661,36 @@ def test_pylint_home() -> None: del os.environ["PYLINTHOME"] +def test_warn_about_old_home(capsys: CaptureFixture) -> None: + """Test that we correctly warn about old_home.""" + # Create old home + old_home = Path(USER_HOME) / OLD_DEFAULT_PYLINT_HOME + old_home.mkdir(parents=True, exist_ok=True) + + # Create spam prevention file + ten_years_ago = datetime.datetime.now() - datetime.timedelta(weeks=520) + new_prevention_file = Path(PYLINT_HOME) / ten_years_ago.strftime( + "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" + ) + with open(new_prevention_file, "w", encoding="utf8") as f: + f.write("") + + # Remove current prevention file + cur_prevention_file = Path(PYLINT_HOME) / datetime.datetime.now().strftime( + "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" + ) + if cur_prevention_file.exists(): + os.remove(cur_prevention_file) + + _warn_about_old_home(Path(PYLINT_HOME)) + + assert not new_prevention_file.exists() + assert cur_prevention_file.exists() + + out = capsys.readouterr() + assert "PYLINTHOME is now" in out.err + + @pytest.mark.usefixtures("pop_pylintrc") def test_pylintrc() -> None: with fake_home(): |