summaryrefslogtreecommitdiff
path: root/tests/lint/unittest_expand_modules.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lint/unittest_expand_modules.py')
-rw-r--r--tests/lint/unittest_expand_modules.py104
1 files changed, 70 insertions, 34 deletions
diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py
index ef98cf575..4d679ad64 100644
--- a/tests/lint/unittest_expand_modules.py
+++ b/tests/lint/unittest_expand_modules.py
@@ -4,10 +4,14 @@
import re
from pathlib import Path
+from typing import Dict, Tuple, Type
import pytest
+from pylint.checkers import BaseChecker
from pylint.lint.expand_modules import _is_in_ignore_list_re, expand_modules
+from pylint.testutils import CheckerTestCase, set_config
+from pylint.utils.utils import get_global_option
def test__is_in_ignore_list_re_match() -> None:
@@ -21,17 +25,6 @@ def test__is_in_ignore_list_re_match() -> None:
assert _is_in_ignore_list_re("src/tests/whatever.xml", patterns)
-def test__is_in_ignore_list_re_nomatch() -> None:
- patterns = [
- re.compile(".*enchilada.*"),
- re.compile("unittest_.*"),
- re.compile(".*tests/.*"),
- ]
- assert not _is_in_ignore_list_re("test_utils.py", patterns)
- assert not _is_in_ignore_list_re("enchilad.py", patterns)
- assert not _is_in_ignore_list_re("src/tests.py", patterns)
-
-
TEST_DIRECTORY = Path(__file__).parent.parent
INIT_PATH = str(TEST_DIRECTORY / "lint/__init__.py")
EXPAND_MODULES = str(TEST_DIRECTORY / "lint/unittest_expand_modules.py")
@@ -84,27 +77,70 @@ init_of_package = {
}
-@pytest.mark.parametrize(
- "files_or_modules,expected",
- [
- ([__file__], [this_file]),
- (
- [Path(__file__).parent],
- [
- init_of_package,
- test_pylinter,
- test_utils,
- this_file_from_init,
- unittest_lint,
- ],
- ),
- ],
-)
-def test_expand_modules(files_or_modules, expected):
- ignore_list, ignore_list_re, ignore_list_paths_re = [], [], []
- modules, errors = expand_modules(
- files_or_modules, ignore_list, ignore_list_re, ignore_list_paths_re
+class TestExpandModules(CheckerTestCase):
+ """Test the expand_modules function while allowing options to be set"""
+
+ class Checker(BaseChecker):
+ """This dummy checker is needed to allow options to be set"""
+
+ name = "checker"
+ msgs: Dict[str, Tuple[str, ...]] = {}
+ options = (("An option", {"An option": "dict"}),)
+
+ CHECKER_CLASS: Type = Checker
+
+ @pytest.mark.parametrize(
+ "files_or_modules,expected",
+ [
+ ([__file__], [this_file]),
+ (
+ [str(Path(__file__).parent)],
+ [
+ init_of_package,
+ test_pylinter,
+ test_utils,
+ this_file_from_init,
+ unittest_lint,
+ ],
+ ),
+ ],
+ )
+ @set_config(ignore_paths="")
+ def test_expand_modules(self, files_or_modules, expected):
+ """Test expand_modules with the default value of ignore-paths"""
+ ignore_list, ignore_list_re = [], []
+ modules, errors = expand_modules(
+ files_or_modules,
+ ignore_list,
+ ignore_list_re,
+ get_global_option(self, "ignore-paths"),
+ )
+ modules.sort(key=lambda d: d["name"])
+ assert modules == expected
+ assert not errors
+
+ @pytest.mark.parametrize(
+ "files_or_modules,expected",
+ [
+ ([__file__], []),
+ (
+ [str(Path(__file__).parent)],
+ [
+ init_of_package,
+ ],
+ ),
+ ],
)
- modules.sort(key=lambda d: d["name"])
- assert modules == expected
- assert not errors
+ @set_config(ignore_paths=".*/lint/.*")
+ def test_expand_modules_with_ignore(self, files_or_modules, expected):
+ """Test expand_modules with a non-default value of ignore-paths"""
+ ignore_list, ignore_list_re = [], []
+ modules, errors = expand_modules(
+ files_or_modules,
+ ignore_list,
+ ignore_list_re,
+ get_global_option(self.checker, "ignore-paths"),
+ )
+ modules.sort(key=lambda d: d["name"])
+ assert modules == expected
+ assert not errors