Skip to content

Commit

Permalink
Better handling of removal in functional conf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Nov 10, 2021
1 parent a4f40fa commit 62f5270
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pylint/testutils/configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest
from pathlib import Path
from typing import Any, Dict, Tuple, Union
from unittest.mock import Mock

from pylint.lint import Run

Expand Down Expand Up @@ -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


Expand All @@ -68,7 +73,7 @@ def get_relative_path(path: str) -> 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]
Expand Down
9 changes: 9 additions & 0 deletions tests/config/functional/toml/toml_with_enable.result.json
Original file line number Diff line number Diff line change
@@ -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"]]
}
}
5 changes: 5 additions & 0 deletions tests/config/functional/toml/toml_with_enable.toml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 16 additions & 2 deletions tests/config/test_functional_config_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"""

# 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,
Expand Down Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 62f5270

Please sign in to comment.