summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-10 10:10:14 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-11-12 18:00:31 +0100
commit88d08e25c41c8a7b937058c452cfdec25700b1e1 (patch)
treef0570744f2ecd3cb3b65cfdf6e33197816385291
parent6626c239e513348ee7ed6133868c86f82bf26b67 (diff)
downloadpylint-git-88d08e25c41c8a7b937058c452cfdec25700b1e1.tar.gz
Better handling of removal in functional conf tests
-rw-r--r--pylint/testutils/configuration_test.py9
-rw-r--r--tests/config/functional/toml/toml_with_enable.result.json9
-rw-r--r--tests/config/functional/toml/toml_with_enable.toml5
-rw-r--r--tests/config/test_functional_config_loading.py18
4 files changed, 37 insertions, 4 deletions
diff --git a/pylint/testutils/configuration_test.py b/pylint/testutils/configuration_test.py
index 00d828b08..723e4afa3 100644
--- a/pylint/testutils/configuration_test.py
+++ b/pylint/testutils/configuration_test.py
@@ -7,6 +7,7 @@ import json
import unittest
from pathlib import Path
from typing import Any, Dict, Tuple, Union
+from unittest.mock import Mock
from pylint.lint import Run
@@ -48,7 +49,11 @@ def get_expected_configuration(
result[key] += value
if EXPECTED_CONF_REMOVE_KEY in to_override:
for key, value in to_override[EXPECTED_CONF_REMOVE_KEY].items():
- result[key] -= value
+ new_value = []
+ for old_value in result[key]:
+ if old_value not in value:
+ new_value.append(old_value)
+ result[key] = new_value
return result
@@ -68,7 +73,7 @@ def get_expected_output(configuration_path: str) -> Tuple[int, str]:
def run_using_a_configuration_file(
configuration_path: Union[Path, str], file_to_lint: str = __file__
-) -> Tuple[unittest.mock.Mock, unittest.mock.Mock, Run]:
+) -> Tuple[Mock, Mock, Run]:
"""Simulate a run with a configuration without really launching the checks."""
configuration_path = str(configuration_path)
args = ["--rcfile", configuration_path, file_to_lint]
diff --git a/tests/config/functional/toml/toml_with_enable.result.json b/tests/config/functional/toml/toml_with_enable.result.json
new file mode 100644
index 000000000..0bdbc840d
--- /dev/null
+++ b/tests/config/functional/toml/toml_with_enable.result.json
@@ -0,0 +1,9 @@
+{
+ "functional_append": {
+ "disable": [["logging-not-lazy"], ["logging-format-interpolation"]],
+ "enable": [["suppressed-message"], ["locally-disabled"]]
+ },
+ "functional_remove": {
+ "disable": [["suppressed-message"], ["locally-disabled"]]
+ }
+}
diff --git a/tests/config/functional/toml/toml_with_enable.toml b/tests/config/functional/toml/toml_with_enable.toml
new file mode 100644
index 000000000..a1e7b65af
--- /dev/null
+++ b/tests/config/functional/toml/toml_with_enable.toml
@@ -0,0 +1,5 @@
+# Check that we can add or remove value in list
+# (This is mostly a check for the functional test themselves)
+[tool.pylint."messages control"]
+disable = "logging-not-lazy,logging-format-interpolation"
+enable = "locally-disabled,suppressed-message"
diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py
index 5d3696c2f..f83921438 100644
--- a/tests/config/test_functional_config_loading.py
+++ b/tests/config/test_functional_config_loading.py
@@ -18,12 +18,13 @@ and ``"functional_remove":``. Check the existing code for example.
"""
# pylint: disable=redefined-outer-name
-
+import logging
from pathlib import Path
from typing import Any, Dict
import pytest
from _pytest.capture import CaptureFixture
+from _pytest.logging import LogCaptureFixture
from pylint.testutils.configuration_test import (
get_expected_configuration,
@@ -60,8 +61,10 @@ def test_functional_config_loading(
configuration_path: str,
default_configuration: Dict[str, Any],
capsys: CaptureFixture,
+ caplog: LogCaptureFixture,
):
"""Functional tests for configurations."""
+ caplog.set_level(logging.INFO)
configuration_path = str(FUNCTIONAL_DIR / configuration_path)
msg = f"Wrong result with configuration {configuration_path}"
expected_code, expected_output = get_expected_output(configuration_path)
@@ -75,5 +78,16 @@ def test_functional_config_loading(
out, err = capsys.readouterr()
# rstrip() applied so we can have a final newline in the expected test file
assert expected_output.rstrip() == out.rstrip(), msg
- assert expected_loaded_configuration == runner.linter.config.__dict__
+ assert sorted(expected_loaded_configuration.keys()) == sorted(
+ runner.linter.config.__dict__.keys()
+ ), msg
+ for key in expected_loaded_configuration:
+ key_msg = f"{msg} for key '{key}':"
+ expected_value = expected_loaded_configuration[key]
+ if isinstance(expected_value, list):
+ assert sorted(expected_value) == sorted(
+ runner.linter.config.__dict__[key]
+ ), key_msg
+ else:
+ assert expected_value == runner.linter.config.__dict__[key], key_msg
assert not err, msg