Skip to content

Commit e24f7d1

Browse files
committed
Add tests for recursive pyproject.toml search
1 parent 1599b2c commit e24f7d1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/config/test_find_default_config_files.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,49 @@ def test_pylintrc_parentdir() -> None:
129129
assert next(config.find_default_config_files()) == expected
130130

131131

132+
@pytest.mark.usefixtures("pop_pylintrc")
133+
def test_pyproject_toml_parentdir() -> None:
134+
"""Test the search of pyproject.toml file in parent directories"""
135+
with tempdir() as chroot:
136+
with fake_home():
137+
chroot_path = Path(chroot)
138+
files = [
139+
"pyproject.toml",
140+
"git/pyproject.toml",
141+
"git/a/pyproject.toml",
142+
"git/a/.git",
143+
"git/a/b/c/__init__.py",
144+
"hg/pyproject.toml",
145+
"hg/a/pyproject.toml",
146+
"hg/a/.hg",
147+
"hg/a/b/c/__init__.py",
148+
"none/sub/__init__.py",
149+
]
150+
testutils.create_files(files)
151+
for config_file in files:
152+
if config_file.endswith("pyproject.toml"):
153+
with open(config_file, "w", encoding="utf-8") as fd:
154+
fd.write('[tool.pylint."messages control"]\n')
155+
with pytest.warns(DeprecationWarning):
156+
assert config.find_pylintrc() is None
157+
results = {
158+
"": chroot_path / "pyproject.toml",
159+
"git": chroot_path / "git" / "pyproject.toml",
160+
"git/a": chroot_path / "git" / "a" / "pyproject.toml",
161+
"git/a/b": chroot_path / "git" / "a" / "pyproject.toml",
162+
"git/a/b/c": chroot_path / "git" / "a" / "pyproject.toml",
163+
"hg": chroot_path / "hg" / "pyproject.toml",
164+
"hg/a": chroot_path / "hg" / "a" / "pyproject.toml",
165+
"hg/a/b": chroot_path / "hg" / "a" / "pyproject.toml",
166+
"hg/a/b/c": chroot_path / "hg" / "a" / "pyproject.toml",
167+
"none": chroot_path / "pyproject.toml",
168+
"none/sub": chroot_path / "pyproject.toml",
169+
}
170+
for basedir, expected in results.items():
171+
os.chdir(chroot_path / basedir)
172+
assert next(config.find_default_config_files(), None) == expected
173+
174+
132175
@pytest.mark.usefixtures("pop_pylintrc")
133176
def test_pylintrc_parentdir_no_package() -> None:
134177
"""Test that we don't find a pylintrc in sub-packages."""

0 commit comments

Comments
 (0)