| # Copyright (c) 2015 Aru Sahni <[email protected]> |
| # Copyright (c) 2016-2018, 2020 Claudiu Popa <[email protected]> |
| # Copyright (c) 2016 Derek Gustafson <[email protected]> |
| # Copyright (c) 2017 Ville Skyttä <[email protected]> |
| # Copyright (c) 2019-2021 Pierre Sassoulas <[email protected]> |
| # Copyright (c) 2019 Ashley Whetter <[email protected]> |
| # Copyright (c) 2020 hippo91 <[email protected]> |
| # Copyright (c) 2020 Anthony Sottile <[email protected]> |
| # Copyright (c) 2021 Marc Mueller <[email protected]> |
| |
| # 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 |
| |
| """Unit tests for the config module.""" |
| |
| import re |
| import sre_constants |
| |
| import pytest |
| |
| from pylint import config |
| |
| RE_PATTERN_TYPE = getattr(re, "Pattern", getattr(re, "_pattern_type", None)) |
| |
| |
| def test__regexp_validator_valid() -> None: |
| result = config.option._regexp_validator(None, None, "test_.*") |
| assert isinstance(result, RE_PATTERN_TYPE) |
| assert result.pattern == "test_.*" |
| |
| |
| def test__regexp_validator_invalid() -> None: |
| with pytest.raises(sre_constants.error): |
| config.option._regexp_validator(None, None, "test_)") |
| |
| |
| def test__csv_validator_no_spaces() -> None: |
| values = ["One", "Two", "Three"] |
| result = config.option._csv_validator(None, 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, 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, None, ",".join(pattern_strings)) |
| for i, regex in enumerate(result): |
| assert isinstance(regex, RE_PATTERN_TYPE) |
| assert regex.pattern == pattern_strings[i] |
| |
| |
| def test__regexp_csv_validator_invalid() -> None: |
| pattern_strings = ["test_.*", "foo\\.bar", "^baz)$"] |
| with pytest.raises(sre_constants.error): |
| config.option._regexp_csv_validator(None, None, ",".join(pattern_strings)) |