summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-10-29 10:15:30 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-03 10:16:38 +0100
commit6283c5aebf34c833c7f79c1e3c21cf3764dc1edd (patch)
treeab7e58080c2667695b0e1eee0e7531d9222483c9
parent72f0f50ada9cafc586e1642259769d5bd9564bd5 (diff)
downloadpylint-git-invalid-toml-config.tar.gz
Add test for current pyproject issuesinvalid-toml-config
-rw-r--r--pylint/config/option_manager_mixin.py19
-rw-r--r--pylint/utils/linterstats.py15
-rw-r--r--tests/config/file_to_lint.py1
-rw-r--r--tests/config/issue_4580/1.toml2
-rw-r--r--tests/config/issue_4580/2.toml2
-rw-r--r--tests/config/issue_4580/3.toml2
-rw-r--r--tests/config/issue_4746/pyproject.toml7
-rw-r--r--tests/config/test_config_pyproject_toml.py35
8 files changed, 73 insertions, 10 deletions
diff --git a/pylint/config/option_manager_mixin.py b/pylint/config/option_manager_mixin.py
index 4f96a32dd..4439238fa 100644
--- a/pylint/config/option_manager_mixin.py
+++ b/pylint/config/option_manager_mixin.py
@@ -309,13 +309,18 @@ class OptionsManagerMixIn:
for section, values in sections_values.items():
# TOML has rich types, convert values to
# strings as ConfigParser expects.
- for option, value in values.items():
- if isinstance(value, bool):
- values[option] = "yes" if value else "no"
- elif isinstance(value, (int, float)):
- values[option] = str(value)
- elif isinstance(value, list):
- values[option] = ",".join(value)
+ if isinstance(values, list):
+ values = ",".join(values)
+ elif isinstance(values, dict):
+ for option, value in values.items():
+ if isinstance(value, bool):
+ values[option] = "yes" if value else "no"
+ elif isinstance(value, (int, float)):
+ values[option] = str(value)
+ elif isinstance(value, list):
+ values[option] = ",".join(value)
+ else:
+ values[option] = str(value)
parser._sections[section.upper()] = values # type: ignore
def load_config_file(self):
diff --git a/pylint/utils/linterstats.py b/pylint/utils/linterstats.py
index f46054455..212aa6dc0 100644
--- a/pylint/utils/linterstats.py
+++ b/pylint/utils/linterstats.py
@@ -285,9 +285,18 @@ class LinterStats:
increase: int,
) -> None:
"""Increase the message type count of an individual message type of a module"""
- self.by_module[modname][type_name] = (
- self.by_module[modname][type_name] + increase
- )
+ if self.by_module.get(modname, None) is None:
+ self.by_module[modname] = ModuleStats(
+ convention=0,
+ error=0,
+ fatal=0,
+ info=0,
+ refactor=0,
+ statement=0,
+ warning=0,
+ )
+ module_stat = self.by_module[modname][type_name]
+ self.by_module[modname][type_name] = module_stat + increase
def reset_message_count(self) -> None:
"""Resets the message type count of the stats object"""
diff --git a/tests/config/file_to_lint.py b/tests/config/file_to_lint.py
new file mode 100644
index 000000000..e4c380d27
--- /dev/null
+++ b/tests/config/file_to_lint.py
@@ -0,0 +1 @@
+"""Perfect module with only documentation for test_config_pyproject_toml.py"""
diff --git a/tests/config/issue_4580/1.toml b/tests/config/issue_4580/1.toml
new file mode 100644
index 000000000..1b291b355
--- /dev/null
+++ b/tests/config/issue_4580/1.toml
@@ -0,0 +1,2 @@
+[tool.pylint]
+load-plugins = []
diff --git a/tests/config/issue_4580/2.toml b/tests/config/issue_4580/2.toml
new file mode 100644
index 000000000..2f8fdb555
--- /dev/null
+++ b/tests/config/issue_4580/2.toml
@@ -0,0 +1,2 @@
+[tool.pylint.imports]
+preferred-modules = { "a"="b" }
diff --git a/tests/config/issue_4580/3.toml b/tests/config/issue_4580/3.toml
new file mode 100644
index 000000000..845f5e8bb
--- /dev/null
+++ b/tests/config/issue_4580/3.toml
@@ -0,0 +1,2 @@
+[tool.pylint.basic]
+name-group = { "a"="b" }
diff --git a/tests/config/issue_4746/pyproject.toml b/tests/config/issue_4746/pyproject.toml
new file mode 100644
index 000000000..5b41d1b89
--- /dev/null
+++ b/tests/config/issue_4746/pyproject.toml
@@ -0,0 +1,7 @@
+[tool.poe.tasks]
+docs = {cmd = "sphinx-build docs build", help = "Build documentation"}
+
+[tool.pylint.MASTER]
+load-plugins = 'pylint_websockets'
+
+format = ["black", "isort"]
diff --git a/tests/config/test_config_pyproject_toml.py b/tests/config/test_config_pyproject_toml.py
new file mode 100644
index 000000000..bcae5b27b
--- /dev/null
+++ b/tests/config/test_config_pyproject_toml.py
@@ -0,0 +1,35 @@
+from pathlib import Path
+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", [{"code": 0}, {"code": 0}, {"code": 0}]],
+ [
+ "issue_4746",
+ [{"code": 2, "out": "Plugin 'pylint_websockets' is impossible to load"}],
+ ],
+ ],
+)
+def test_config_pyproject_toml(pyproject_toml_path, expected_results, capsys):
+ pyproject_toml_paths = (HERE / pyproject_toml_path).iterdir()
+ for toml_path, expected_result in zip(pyproject_toml_paths, expected_results):
+ with patch(
+ "sys.argv",
+ ["pylint", "--rcfile", str(toml_path), str(HERE / "file_to_lint.py")],
+ ):
+ try:
+ run_pylint()
+ except SystemExit as ex:
+ out, err = capsys.readouterr()
+ msg = f"Wrong result with configuration {toml_path}"
+ assert expected_result.get("out", "¤") in out or not out, msg
+ assert not err or expected_result.get("err", "¤") in err, msg
+ assert ex.code == expected_result.get("code"), msg