diff options
Diffstat (limited to 'tests/config/test_find_default_config_files.py')
-rw-r--r-- | tests/config/test_find_default_config_files.py | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/tests/config/test_find_default_config_files.py b/tests/config/test_find_default_config_files.py index 2fd66544d..0b513a3d5 100644 --- a/tests/config/test_find_default_config_files.py +++ b/tests/config/test_find_default_config_files.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations @@ -130,6 +130,47 @@ def test_pylintrc_parentdir() -> None: @pytest.mark.usefixtures("pop_pylintrc") +def test_pyproject_toml_parentdir() -> None: + """Test the search of pyproject.toml file in parent directories""" + with tempdir() as chroot: + with fake_home(): + chroot_path = Path(chroot) + files = [ + "pyproject.toml", + "git/pyproject.toml", + "git/a/pyproject.toml", + "git/a/.git", + "git/a/b/c/__init__.py", + "hg/pyproject.toml", + "hg/a/pyproject.toml", + "hg/a/.hg", + "hg/a/b/c/__init__.py", + "none/sub/__init__.py", + ] + testutils.create_files(files) + for config_file in files: + if config_file.endswith("pyproject.toml"): + with open(config_file, "w", encoding="utf-8") as fd: + fd.write('[tool.pylint."messages control"]\n') + results = { + "": chroot_path / "pyproject.toml", + "git": chroot_path / "git" / "pyproject.toml", + "git/a": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b/c": chroot_path / "git" / "a" / "pyproject.toml", + "hg": chroot_path / "hg" / "pyproject.toml", + "hg/a": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b/c": chroot_path / "hg" / "a" / "pyproject.toml", + "none": chroot_path / "pyproject.toml", + "none/sub": chroot_path / "pyproject.toml", + } + for basedir, expected in results.items(): + os.chdir(chroot_path / basedir) + assert next(config.find_default_config_files(), None) == expected + + +@pytest.mark.usefixtures("pop_pylintrc") def test_pylintrc_parentdir_no_package() -> None: """Test that we don't find a pylintrc in sub-packages.""" with tempdir() as chroot: @@ -138,8 +179,6 @@ def test_pylintrc_parentdir_no_package() -> None: testutils.create_files( ["a/pylintrc", "a/b/pylintrc", "a/b/c/d/__init__.py"] ) - with pytest.warns(DeprecationWarning): - assert config.find_pylintrc() is None results = { "a": chroot_path / "a" / "pylintrc", "a/b": chroot_path / "a" / "b" / "pylintrc", @@ -244,7 +283,7 @@ def test_cfg_has_config(content: str, expected: bool, tmp_path: Path) -> None: def test_non_existent_home() -> None: """Test that we handle a non-existent home directory. - Reported in https://github.com/PyCQA/pylint/issues/6802. + Reported in https://github.com/pylint-dev/pylint/issues/6802. """ with mock.patch("pathlib.Path.home", side_effect=RuntimeError): current_dir = os.getcwd() @@ -258,7 +297,7 @@ def test_non_existent_home() -> None: def test_permission_error() -> None: """Test that we handle PermissionError correctly in find_default_config_files. - Reported in https://github.com/PyCQA/pylint/issues/7169. + Reported in https://github.com/pylint-dev/pylint/issues/7169. """ with mock.patch("pathlib.Path.is_file", side_effect=PermissionError): list(config.find_default_config_files()) |