summaryrefslogtreecommitdiff
path: root/tests/checkers
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2023-01-28 18:08:28 +0100
committerGitHub <noreply@github.com>2023-01-28 18:08:28 +0100
commitacb28d8fcefb06179d9e6528ba14dd099e12ecfa (patch)
tree1f8f68dd9a3f00c375ec743010980452e821cbd8 /tests/checkers
parent2cfc8f5d38a2e0ea46be7b3908729cca8c8fb8c4 (diff)
downloadpylint-git-acb28d8fcefb06179d9e6528ba14dd099e12ecfa.tar.gz
Add `--allow-reexport-from-package` option (#8124)
Diffstat (limited to 'tests/checkers')
-rw-r--r--tests/checkers/unittest_imports.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/checkers/unittest_imports.py b/tests/checkers/unittest_imports.py
index ed5c13805..40aa8432a 100644
--- a/tests/checkers/unittest_imports.py
+++ b/tests/checkers/unittest_imports.py
@@ -137,3 +137,46 @@ class TestImportsChecker(CheckerTestCase):
assert "Prefer importing 'sys' instead of 'os'" in output
# assert there were no errors
assert len(errors) == 0
+
+ @staticmethod
+ def test_allow_reexport_package(capsys: CaptureFixture[str]) -> None:
+ """Test --allow-reexport-from-package option."""
+
+ # Option disabled - useless-import-alias should always be emitted
+ Run(
+ [
+ f"{os.path.join(REGR_DATA, 'allow_reexport')}",
+ "--allow-reexport-from-package=no",
+ "-sn",
+ ],
+ exit=False,
+ )
+ output, errors = capsys.readouterr()
+ assert len(output.split("\n")) == 5
+ assert (
+ "__init__.py:1:0: C0414: Import alias does not rename original package (useless-import-alias)"
+ in output
+ )
+ assert (
+ "file.py:2:0: C0414: Import alias does not rename original package (useless-import-alias)"
+ in output
+ )
+ assert len(errors) == 0
+
+ # Option enabled - useless-import-alias should only be emitted for 'file.py'
+ Run(
+ [
+ f"{os.path.join(REGR_DATA, 'allow_reexport')}",
+ "--allow-reexport-from-package=yes",
+ "-sn",
+ ],
+ exit=False,
+ )
+ output, errors = capsys.readouterr()
+ assert len(output.split("\n")) == 3
+ assert "__init__.py" not in output
+ assert (
+ "file.py:2:0: C0414: Import alias does not rename original package (useless-import-alias)"
+ in output
+ )
+ assert len(errors) == 0