forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crashes during toml configuration parsing
Add test for current pyproject.toml issues Add a 'bad-configuration-option-value' message for bad toml configuration We do not catch all the problem in toml because we don't know what is expected so we can't recommend. See pylint-dev#5259 We can detect bad top level option when reading the toml
- Loading branch information
1 parent
e2c7577
commit 946adb2
Showing
15 changed files
with
163 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Perfect module with only documentation for test_config_pyproject_toml.py""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[tool.pylint."messages control"] | ||
disable = "logging-not-lazy,logging-format-interpolation" | ||
jobs = "10" | ||
reports = "yes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint.basic] | ||
name-group = { "a"="b" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint.imports] | ||
preferred-modules = { "a"="b" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint] | ||
load-plugins = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[tool.pylint] | ||
# Both disable and load-plugins are not top level section | ||
load-plugins = [] | ||
disable = "logging-not-lazy,logging-format-interpolation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Both disable and load-plugins are not top level section | ||
[tool.pylint."imports"] | ||
disable = [ | ||
"logging-not-lazy", | ||
"logging-format-interpolation", | ||
] | ||
preferred-modules = { "a"="b" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[tool.pylint."messages control"] | ||
disable = [ | ||
"logging-not-lazy", | ||
"logging-format-interpolation", | ||
] | ||
jobs = 10 | ||
reports = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.pylint] | ||
disable = "logging-not-lazy,logging-format-interpolation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The pylint_websockets plugin does not exist and therefore this toml is invalid | ||
[tool.poe.tasks] | ||
docs = {cmd = "sphinx-build docs build", help = "Build documentation"} | ||
|
||
[tool.pylint.MASTER] | ||
load-plugins = 'pylint_websockets' | ||
|
||
format = ["black", "isort"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from pathlib import Path | ||
from typing import List | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from pylint import run_pylint | ||
|
||
HERE = Path(__file__).parent | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"pyproject_toml_path,expected_results", | ||
[ | ||
[ | ||
"issue_4580", | ||
{ | ||
"basic_example.toml": {"code": 0}, | ||
"correct_basic_name_group.toml": {"code": 0}, | ||
"correct_import_preferred_module.toml": {"code": 0}, | ||
"empty_list.toml": { | ||
"code": 2, | ||
"out": "encountered 'load-plugins' : '[]'", | ||
}, | ||
"invalid_data_for_basic.toml": { | ||
"code": 2, | ||
"out": "encountered 'load-plugins' : '[]'", | ||
}, | ||
"invalid_data_for_import.toml": {"code": 0}, | ||
"rich_types.toml": {"code": 0}, | ||
"top_level_disable.toml": { | ||
"code": 2, | ||
"out": "encountered 'disable' : 'logging-not-lazy,", | ||
}, | ||
}, | ||
], | ||
[ | ||
"issue_4746", | ||
{ | ||
"loaded_plugin_does_not_exists.toml": { | ||
"code": 2, | ||
"out": "'pylint_websockets' is impossible to load", | ||
} | ||
}, | ||
], | ||
], | ||
) | ||
def test_config_pyproject_toml(pyproject_toml_path, expected_results, capsys): | ||
pyproject_toml_paths: List[Path] = (HERE / pyproject_toml_path).iterdir() | ||
for toml_path in pyproject_toml_paths: | ||
expected_result = expected_results[toml_path.name] | ||
file_to_lint = str(HERE / "file_to_lint.py") | ||
with patch( | ||
"sys.argv", | ||
["pylint", "--rcfile", str(toml_path), file_to_lint, "-r", "n"], | ||
): | ||
try: | ||
run_pylint() | ||
except SystemExit as ex: | ||
out, err = capsys.readouterr() | ||
msg = f"Wrong result with configuration {toml_path}" | ||
if "out" not in expected_result: | ||
assert not out, msg | ||
else: | ||
assert expected_result["out"] in out, msg | ||
if "err" not in expected_result: | ||
assert not err, msg | ||
else: | ||
assert expected_result["err"] in err, msg | ||
assert ex.code == expected_result.get("code"), msg |