summaryrefslogtreecommitdiff
path: root/tests/unittest_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittest_config.py')
-rw-r--r--tests/unittest_config.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unittest_config.py b/tests/unittest_config.py
index 9be02fc4c..9979aa41b 100644
--- a/tests/unittest_config.py
+++ b/tests/unittest_config.py
@@ -16,10 +16,14 @@
import re
import sre_constants
+from typing import Dict, Tuple, Type
import pytest
from pylint import config
+from pylint.checkers import BaseChecker
+from pylint.testutils import CheckerTestCase, set_config
+from pylint.utils.utils import get_global_option
RE_PATTERN_TYPE = getattr(re, "Pattern", getattr(re, "_pattern_type", None))
@@ -65,3 +69,33 @@ 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))
+
+
+class TestPyLinterOptionSetters(CheckerTestCase):
+ """Class to check the set_config decorator and get_global_option util
+ for options declared in PyLinter."""
+
+ class Checker(BaseChecker):
+ name = "checker"
+ msgs: Dict[str, Tuple[str, ...]] = {}
+ options = (("An option", {"An option": "dict"}),)
+
+ 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 = get_global_option(self.checker, "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 = get_global_option(self.checker, "ignore-paths")
+
+ # pylint: disable-next=use-implicit-booleaness-not-comparison
+ assert options == []