diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-04-01 21:45:59 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-04-03 22:49:21 +0200 |
commit | fb2ae7bc741061da2c1ae77c06fd643b648b121b (patch) | |
tree | 635591f28e4c90eddbf50ccc7b4877690a7a31df | |
parent | dbcf928e5c9b3bc87b63e305e75046a91eade6c7 (diff) | |
download | pylint-git-fb2ae7bc741061da2c1ae77c06fd643b648b121b.tar.gz |
Add very basic tests for expand modules
-rw-r--r-- | tests/conftest.py | 6 | ||||
-rw-r--r-- | tests/lint/unittest_expand_modules.py | 59 |
2 files changed, 64 insertions, 1 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index e2762091d..5c2567d11 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ # pylint: disable=redefined-outer-name # pylint: disable=no-name-in-module import os +from pathlib import Path import pytest @@ -9,6 +10,11 @@ from pylint.lint import PyLinter from pylint.testutils import MinimalTestReporter +@pytest.fixture() +def tests_directory(): + return Path(__file__).parent + + @pytest.fixture def linter(checker, register, enable, disable, reporter): _linter = PyLinter() diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py index 2a6b072ff..670ed1ed4 100644 --- a/tests/lint/unittest_expand_modules.py +++ b/tests/lint/unittest_expand_modules.py @@ -3,8 +3,11 @@ import re +from pathlib import Path -from pylint.lint.expand_modules import _basename_in_ignore_list_re +import pytest + +from pylint.lint.expand_modules import _basename_in_ignore_list_re, expand_modules def test__basename_in_ignore_list_re_match(): @@ -17,3 +20,57 @@ def test__basename_in_ignore_list_re_nomatch(): patterns = [re.compile(".*enchilada.*"), re.compile("unittest_.*")] assert not _basename_in_ignore_list_re("test_utils.py", patterns) assert not _basename_in_ignore_list_re("enchilad.py", patterns) + + +TEST_DIRECTORY = str(Path(__file__).parent.parent) +INIT_PATH = "%s/lint/__init__.py" % TEST_DIRECTORY +EXPAND_MODULES = "%s/lint/unittest_expand_modules.py" % TEST_DIRECTORY +this_file = { + "basename": "lint.unittest_expand_modules", + "basepath": EXPAND_MODULES, + "isarg": True, + "name": "lint.unittest_expand_modules", + "path": EXPAND_MODULES, +} + +this_file_from_init = { + "basename": "lint", + "basepath": INIT_PATH, + "isarg": False, + "name": "lint.unittest_expand_modules", + "path": EXPAND_MODULES, +} + +unittest_lint = { + "basename": "lint", + "basepath": INIT_PATH, + "isarg": False, + "name": "lint.unittest_lint", + "path": "%s/lint/unittest_lint.py" % TEST_DIRECTORY, +} + + +init_of_package = { + "basename": "lint", + "basepath": INIT_PATH, + "isarg": True, + "name": "lint", + "path": INIT_PATH, +} + + +@pytest.mark.parametrize( + "files_or_modules,expected", + [ + ([__file__], [this_file]), + ( + [Path(__file__).parent], + [init_of_package, this_file_from_init, unittest_lint], + ), + ], +) +def test_expand_modules(files_or_modules, expected): + ignore_list, ignore_list_re = [], [] + modules, errors = expand_modules(files_or_modules, ignore_list, ignore_list_re) + assert modules == expected + assert not errors |