diff options
Diffstat (limited to 'tests/config')
26 files changed, 78 insertions, 254 deletions
diff --git a/tests/config/conftest.py b/tests/config/conftest.py index 491b16267..a5f9a7125 100644 --- a/tests/config/conftest.py +++ b/tests/config/conftest.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from pathlib import Path diff --git a/tests/config/file_to_lint.py b/tests/config/file_to_lint.py index b6a8c14c8..174cc5609 100644 --- a/tests/config/file_to_lint.py +++ b/tests/config/file_to_lint.py @@ -1,5 +1,5 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Perfect module with only documentation for configuration tests.""" diff --git a/tests/config/functional/ini/pylintrc_with_deleted_message.8.out b/tests/config/functional/ini/pylintrc_with_deleted_message.8.out index bb7bad8d9..61044918d 100644 --- a/tests/config/functional/ini/pylintrc_with_deleted_message.8.out +++ b/tests/config/functional/ini/pylintrc_with_deleted_message.8.out @@ -1,3 +1,3 @@ ************* Module {abspath} -{relpath}:1:0: R0022: Useless option value for '--disable', 'buffer-builtin' was removed from pylint, see https://github.com/PyCQA/pylint/pull/4942. (useless-option-value) -{relpath}:1:0: R0022: Useless option value for '--enable', 'cmp-builtin' was removed from pylint, see https://github.com/PyCQA/pylint/pull/4942. (useless-option-value) +{relpath}:1:0: R0022: Useless option value for '--disable', 'buffer-builtin' was removed from pylint, see https://github.com/pylint-dev/pylint/pull/4942. (useless-option-value) +{relpath}:1:0: R0022: Useless option value for '--enable', 'cmp-builtin' was removed from pylint, see https://github.com/pylint-dev/pylint/pull/4942. (useless-option-value) diff --git a/tests/config/functional/ini/pylintrc_with_deleted_message.ini b/tests/config/functional/ini/pylintrc_with_deleted_message.ini index 51b821750..89eaa715e 100644 --- a/tests/config/functional/ini/pylintrc_with_deleted_message.ini +++ b/tests/config/functional/ini/pylintrc_with_deleted_message.ini @@ -1,5 +1,5 @@ # Check that we raise an informational when a deleted messages exists in a .pylintrc file -# See https://github.com/PyCQA/pylint/issues/6794 +# See https://github.com/pylint-dev/pylint/issues/6794 [messages control] disable = logging-not-lazy, buffer-builtin enable = useless-option-value, locally-disabled, cmp-builtin diff --git a/tests/config/functional/ini/pylintrc_with_missing_comma.ini b/tests/config/functional/ini/pylintrc_with_missing_comma.ini index a30efed21..2242a23a1 100644 --- a/tests/config/functional/ini/pylintrc_with_missing_comma.ini +++ b/tests/config/functional/ini/pylintrc_with_missing_comma.ini @@ -1,5 +1,5 @@ # Check that we raise an warning when commas are missing in INI .pylintrc file -# See https://github.com/PyCQA/pylint/issues/3122 +# See https://github.com/pylint-dev/pylint/issues/3122 [messages control] disable = logging-not-lazylogging-format-interpolation enable = locally-disabled diff --git a/tests/config/functional/ini/pylintrc_with_multi_line_init_hook.ini b/tests/config/functional/ini/pylintrc_with_multi_line_init_hook.ini index 015246d5a..e1cd6876a 100644 --- a/tests/config/functional/ini/pylintrc_with_multi_line_init_hook.ini +++ b/tests/config/functional/ini/pylintrc_with_multi_line_init_hook.ini @@ -1,4 +1,4 @@ -# Reported in https://github.com/PyCQA/pylint/issues/6888 +# Reported in https://github.com/pylint-dev/pylint/issues/6888 [MASTER] init-hook= try: import pylint_venv diff --git a/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini index 8b10877ed..415f57b0f 100644 --- a/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini +++ b/tests/config/functional/ini/pylintrc_with_quoted_init_hook.ini @@ -1,4 +1,4 @@ # Check that we support quoted init-hooks -# See https://github.com/PyCQA/pylint/issues/7006 +# See https://github.com/pylint-dev/pylint/issues/7006 [MAIN] init-hook='print("I should just print")' diff --git a/tests/config/functional/setup_cfg/deprecate_master/setup.cfg b/tests/config/functional/setup_cfg/deprecate_master/setup.cfg deleted file mode 100644 index fd6381646..000000000 --- a/tests/config/functional/setup_cfg/deprecate_master/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -# Test the deprecation of MASTER -[MASTER] -persistent=no diff --git a/tests/config/functional/setup_cfg/deprecate_master/setup.result.json b/tests/config/functional/setup_cfg/deprecate_master/setup.result.json deleted file mode 100644 index b66b78598..000000000 --- a/tests/config/functional/setup_cfg/deprecate_master/setup.result.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "persistent": false -} diff --git a/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg index 51a2c307b..042f53a83 100644 --- a/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg +++ b/tests/config/functional/setup_cfg/identical_name_in_flake8/setup.cfg @@ -1,4 +1,4 @@ -# Test for the behavior of https://github.com/PyCQA/pylint/issues/4371 +# Test for the behavior of https://github.com/pylint-dev/pylint/issues/4371 [pylint.MAIN] persistent=no ignore = migrations diff --git a/tests/config/functional/setup_cfg/issue_4272/option_in_wrong_section.cfg b/tests/config/functional/setup_cfg/issue_4272/option_in_wrong_section.cfg index b045873c9..7a1d778c7 100644 --- a/tests/config/functional/setup_cfg/issue_4272/option_in_wrong_section.cfg +++ b/tests/config/functional/setup_cfg/issue_4272/option_in_wrong_section.cfg @@ -1,4 +1,4 @@ -# Test for the behaviour of https://github.com/PyCQA/pylint/issues/4272 +# Test for the behaviour of https://github.com/pylint-dev/pylint/issues/4272 [pylint.NOTMAIN] load-plugins=pylint.extensions.bad_builtin [pylint.MAIN] diff --git a/tests/config/functional/toml/issue_3122/toml_with_missing_comma.toml b/tests/config/functional/toml/issue_3122/toml_with_missing_comma.toml index da810e832..1c2ee3031 100644 --- a/tests/config/functional/toml/issue_3122/toml_with_missing_comma.toml +++ b/tests/config/functional/toml/issue_3122/toml_with_missing_comma.toml @@ -1,5 +1,5 @@ # Check that we raise an error when a comma is missing -# See https://github.com/PyCQA/pylint/issues/3122 +# See https://github.com/pylint-dev/pylint/issues/3122 [tool.pylint."messages control"] disable = "logging-not-lazylogging-format-interpolation,missing-docstring" enable = "locally-disabledsuppressed-message,missing-module-docstring" diff --git a/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml index 4d3f753d0..7ef4de4bf 100644 --- a/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml +++ b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml @@ -1,4 +1,4 @@ -# This crashed previously see https://github.com/PyCQA/pylint/issues/3181 +# This crashed previously see https://github.com/pylint-dev/pylint/issues/3181 [tool.pylint] max-line-length = 120 disable = ["C0121"] diff --git a/tests/config/functional/toml/unknown_msgid/enable_unknown_msgid.toml b/tests/config/functional/toml/unknown_msgid/enable_unknown_msgid.toml index 691883527..65fe56090 100644 --- a/tests/config/functional/toml/unknown_msgid/enable_unknown_msgid.toml +++ b/tests/config/functional/toml/unknown_msgid/enable_unknown_msgid.toml @@ -1,5 +1,5 @@ # Check the behavior for unkonwn symbol/msgid -# (Originally) reported in https://github.com/PyCQA/pylint/pull/6293 +# (Originally) reported in https://github.com/pylint-dev/pylint/pull/6293 [tool.pylint."messages control"] disable = "logging-not-layzy,logging-format-interpolation" diff --git a/tests/config/functional/tox/unrecognized_options/tox.ini b/tests/config/functional/tox/unrecognized_options/tox.ini index 7bc38df51..e5db6d116 100644 --- a/tests/config/functional/tox/unrecognized_options/tox.ini +++ b/tests/config/functional/tox/unrecognized_options/tox.ini @@ -1,4 +1,4 @@ -; Test for https://github.com/PyCQA/pylint/issues/6800 +; Test for https://github.com/pylint-dev/pylint/issues/6800 [tox] skipsdist = True diff --git a/tests/config/pylint_config/test_pylint_config_generate.py b/tests/config/pylint_config/test_pylint_config_generate.py index adf7129a5..61f158aef 100644 --- a/tests/config/pylint_config/test_pylint_config_generate.py +++ b/tests/config/pylint_config/test_pylint_config_generate.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Test for the 'pylint-config generate' command.""" diff --git a/tests/config/pylint_config/test_pylint_config_help.py b/tests/config/pylint_config/test_pylint_config_help.py index fcd57894a..5393a28fb 100644 --- a/tests/config/pylint_config/test_pylint_config_help.py +++ b/tests/config/pylint_config/test_pylint_config_help.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Test for the 'pylint-config generate' command.""" diff --git a/tests/config/pylint_config/test_pylint_config_utils.py b/tests/config/pylint_config/test_pylint_config_utils.py index d41afec1d..b68e331fd 100644 --- a/tests/config/pylint_config/test_pylint_config_utils.py +++ b/tests/config/pylint_config/test_pylint_config_utils.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Test for the 'pylint-config' utils.""" diff --git a/tests/config/pylint_config/test_run_pylint_config.py b/tests/config/pylint_config/test_run_pylint_config.py index 9795e2183..1d282ed86 100644 --- a/tests/config/pylint_config/test_run_pylint_config.py +++ b/tests/config/pylint_config/test_run_pylint_config.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Test for the 'pylint-config generate' command.""" diff --git a/tests/config/test_argparse_config.py b/tests/config/test_argparse_config.py index a9d7f70c2..dfa0fd4dd 100644 --- a/tests/config/test_argparse_config.py +++ b/tests/config/test_argparse_config.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """Test for the (new) implementation of option parsing with argparse""" diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 5eab597fd..ff49d901e 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations @@ -155,7 +155,7 @@ def test_short_verbose(capsys: CaptureFixture) -> None: def test_argument_separator() -> None: """Check that we support using '--' to separate argument types. - Reported in https://github.com/PyCQA/pylint/issues/7003. + Reported in https://github.com/pylint-dev/pylint/issues/7003. """ runner = Run(["--", str(EMPTY_MODULE)], exit=False) assert not runner.linter.stats.by_msg diff --git a/tests/config/test_deprecations.py b/tests/config/test_deprecations.py deleted file mode 100644 index 453a460d8..000000000 --- a/tests/config/test_deprecations.py +++ /dev/null @@ -1,121 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -"""Test for deprecation warnings in the config module.""" - - -import warnings - -import pytest - -from pylint.checkers import BaseChecker -from pylint.lint import PyLinter -from pylint.utils import get_global_option - - -class SampleChecker(BaseChecker): - options = (("test-opt", {"action": "store_true", "help": "help message"}),) - - -class SampleCheckerTwo(BaseChecker): - options = ( - ("test-opt-two", {"action": "store", "type": "string", "help": "help message"}), - ) - - -class SampleCheckerThree(BaseChecker): - options = ( - ( - "test-opt-three", - {"action": "store_true", "level": 1, "help": "help message"}, - ), - ) - - -class TestDeprecationArgumentsManager: - """Tests for deprecation warnings in the ArgumentsManager class.""" - - linter = PyLinter() - - @classmethod - def setup_class(cls) -> None: - checker = SampleChecker(cls.linter) - cls.linter.register_checker(checker) - with pytest.warns(DeprecationWarning): - cls.linter.register_options_provider(checker) - - def test_load_configuration(self) -> None: - """Test that load_configuration emits a DeprecationWarning.""" - - with pytest.warns(DeprecationWarning): - self.linter.load_configuration(test_opt=True) - - def test_load_configuration_from_config(self) -> None: - """Test that load_configuration_from_config emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.load_configuration_from_config({"test_opt": True}) - - def test_help_with_level(self) -> None: - """Test that help with a level argument raises a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.help(1) - - with pytest.warns(DeprecationWarning): - self.linter.help(level=1) - - with warnings.catch_warnings(): - warnings.simplefilter("error") - self.linter.help() - - def test_register_options_provider_load_defaults(self) -> None: - """Test that register_options_provider and load_defaults emits a DeprecationWarning.""" - checker = BaseChecker(self.linter) - with pytest.warns(DeprecationWarning): - self.linter.register_options_provider(checker) - with pytest.warns(DeprecationWarning): - self.linter.load_defaults() - - def test_get_global_option(self) -> None: - """Test that get_global_option emits a DeprecationWarning.""" - checker = BaseChecker(self.linter) - with pytest.warns(DeprecationWarning): - get_global_option(checker, "test-opt") # type: ignore[call-overload] - - def test_read_config_file(self) -> None: - """Test that read_config_file emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.read_config_file() - - def test_load_config_file(self) -> None: - """Test that load_config_file emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.load_config_file() - - def test_load_command_line_configuration(self) -> None: - """Test that load_command_line_configuration emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.load_command_line_configuration([]) - - def test_cb_set_provider_option(self) -> None: - """Test that cb_set_provider_option emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.cb_set_provider_option(None, "--test-opt", True, None) - - def test_level_attribute(self) -> None: - """Test that the level attribute emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - self.linter.level = 1 - - with pytest.warns(DeprecationWarning): - assert self.linter.level is not None - - def test_no_default_in_optdict(self) -> None: - """Test that not having a default value in a optiondict emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - SampleCheckerTwo(self.linter) - - def test_no_level_in_optdict(self) -> None: - """Test that not having a level value in a optiondict emits a DeprecationWarning.""" - with pytest.warns(DeprecationWarning): - SampleCheckerThree(self.linter) diff --git a/tests/config/test_find_default_config_files.py b/tests/config/test_find_default_config_files.py index 2fd66544d..0b513a3d5 100644 --- a/tests/config/test_find_default_config_files.py +++ b/tests/config/test_find_default_config_files.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from __future__ import annotations @@ -130,6 +130,47 @@ def test_pylintrc_parentdir() -> None: @pytest.mark.usefixtures("pop_pylintrc") +def test_pyproject_toml_parentdir() -> None: + """Test the search of pyproject.toml file in parent directories""" + with tempdir() as chroot: + with fake_home(): + chroot_path = Path(chroot) + files = [ + "pyproject.toml", + "git/pyproject.toml", + "git/a/pyproject.toml", + "git/a/.git", + "git/a/b/c/__init__.py", + "hg/pyproject.toml", + "hg/a/pyproject.toml", + "hg/a/.hg", + "hg/a/b/c/__init__.py", + "none/sub/__init__.py", + ] + testutils.create_files(files) + for config_file in files: + if config_file.endswith("pyproject.toml"): + with open(config_file, "w", encoding="utf-8") as fd: + fd.write('[tool.pylint."messages control"]\n') + results = { + "": chroot_path / "pyproject.toml", + "git": chroot_path / "git" / "pyproject.toml", + "git/a": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b": chroot_path / "git" / "a" / "pyproject.toml", + "git/a/b/c": chroot_path / "git" / "a" / "pyproject.toml", + "hg": chroot_path / "hg" / "pyproject.toml", + "hg/a": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b": chroot_path / "hg" / "a" / "pyproject.toml", + "hg/a/b/c": chroot_path / "hg" / "a" / "pyproject.toml", + "none": chroot_path / "pyproject.toml", + "none/sub": chroot_path / "pyproject.toml", + } + for basedir, expected in results.items(): + os.chdir(chroot_path / basedir) + assert next(config.find_default_config_files(), None) == expected + + +@pytest.mark.usefixtures("pop_pylintrc") def test_pylintrc_parentdir_no_package() -> None: """Test that we don't find a pylintrc in sub-packages.""" with tempdir() as chroot: @@ -138,8 +179,6 @@ def test_pylintrc_parentdir_no_package() -> None: testutils.create_files( ["a/pylintrc", "a/b/pylintrc", "a/b/c/d/__init__.py"] ) - with pytest.warns(DeprecationWarning): - assert config.find_pylintrc() is None results = { "a": chroot_path / "a" / "pylintrc", "a/b": chroot_path / "a" / "b" / "pylintrc", @@ -244,7 +283,7 @@ def test_cfg_has_config(content: str, expected: bool, tmp_path: Path) -> None: def test_non_existent_home() -> None: """Test that we handle a non-existent home directory. - Reported in https://github.com/PyCQA/pylint/issues/6802. + Reported in https://github.com/pylint-dev/pylint/issues/6802. """ with mock.patch("pathlib.Path.home", side_effect=RuntimeError): current_dir = os.getcwd() @@ -258,7 +297,7 @@ def test_non_existent_home() -> None: def test_permission_error() -> None: """Test that we handle PermissionError correctly in find_default_config_files. - Reported in https://github.com/PyCQA/pylint/issues/7169. + Reported in https://github.com/pylint-dev/pylint/issues/7169. """ with mock.patch("pathlib.Path.is_file", side_effect=PermissionError): list(config.find_default_config_files()) diff --git a/tests/config/test_functional_config_loading.py b/tests/config/test_functional_config_loading.py index d5a2ba7ca..0bbfe50ff 100644 --- a/tests/config/test_functional_config_loading.py +++ b/tests/config/test_functional_config_loading.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt """This launches the configuration functional tests. This permits to test configuration files by providing a file with the appropriate extension in the ``tests/config/functional`` diff --git a/tests/config/test_per_directory_config.py b/tests/config/test_per_directory_config.py index 85d918a21..b888dd405 100644 --- a/tests/config/test_per_directory_config.py +++ b/tests/config/test_per_directory_config.py @@ -1,6 +1,6 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt +# For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE +# Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt from pathlib import Path diff --git a/tests/config/unittest_config.py b/tests/config/unittest_config.py deleted file mode 100644 index 343663602..000000000 --- a/tests/config/unittest_config.py +++ /dev/null @@ -1,88 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -"""Unit tests for the config module.""" - -from __future__ import annotations - -import re - -import pytest - -from pylint import config -from pylint.checkers import BaseChecker -from pylint.testutils import CheckerTestCase, set_config -from pylint.typing import MessageDefinitionTuple - - -def test__regexp_validator_valid() -> None: - result = config.option._regexp_validator(None, "", "test_.*") - assert isinstance(result, re.Pattern) - assert result.pattern == "test_.*" - - -def test__regexp_validator_invalid() -> None: - with pytest.raises(re.error): - config.option._regexp_validator(None, "", "test_)") - - -def test__csv_validator_no_spaces() -> None: - values = ["One", "Two", "Three"] - result = config.option._csv_validator(None, "", ",".join(values)) - assert isinstance(result, list) - assert len(result) == 3 - for i, value in enumerate(values): - assert result[i] == value - - -def test__csv_validator_spaces() -> None: - values = ["One", "Two", "Three"] - result = config.option._csv_validator(None, "", ", ".join(values)) - assert isinstance(result, list) - assert len(result) == 3 - for i, value in enumerate(values): - assert result[i] == value - - -def test__regexp_csv_validator_valid() -> None: - pattern_strings = ["test_.*", "foo\\.bar", "^baz$"] - result = config.option._regexp_csv_validator(None, "", ",".join(pattern_strings)) - for i, regex in enumerate(result): - assert isinstance(regex, re.Pattern) - assert regex.pattern == pattern_strings[i] - - -def test__regexp_csv_validator_invalid() -> None: - pattern_strings = ["test_.*", "foo\\.bar", "^baz)$"] - with pytest.raises(re.error): - config.option._regexp_csv_validator(None, "", ",".join(pattern_strings)) - - -class TestPyLinterOptionSetters(CheckerTestCase): - """Class to check the set_config decorator for options declared in PyLinter.""" - - class Checker(BaseChecker): - name = "checker" - msgs: dict[str, MessageDefinitionTuple] = {} - options = (("test-opt", {"action": "store_true", "help": "help message"}),) - - CHECKER_CLASS: type = Checker - - @set_config(ignore_paths=".*/tests/.*,.*\\ignore\\.*") - def test_ignore_paths_with_value(self) -> None: - """Test ignore-paths option with value.""" - options = self.linter.config.ignore_paths - - assert any(i.match("dir/tests/file.py") for i in options) - assert any(i.match("dir\\tests\\file.py") for i in options) - assert any(i.match("dir/ignore/file.py") for i in options) - assert any(i.match("dir\\ignore\\file.py") for i in options) - - def test_ignore_paths_with_no_value(self) -> None: - """Test ignore-paths option with no value. - Compare against actual list to see if validator works. - """ - options = self.linter.config.ignore_paths - - assert options == [] |