Skip to content

Commit c33f89d

Browse files
committed
Refactor test cases for import validation rules
1 parent 88cdcfd commit c33f89d

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

tests/test_plugin.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,16 @@
99
@pytest.mark.parametrize(
1010
("input_source", "expected_output"),
1111
[
12-
# COP001: Use module import when importing more than two names
13-
("from x import a, b, c", ["COP001"]),
1412
# COP002: Import standard library modules as whole modules
1513
("from os import name", ["COP002"]),
16-
# No violation: unittest mock is allowed
17-
("from unittest import mock", []),
18-
# No violation: importlib resources submodules are allowed
19-
("from importlib import resources", []),
20-
("from importlib import metadata", []),
2114
# COP002: Even resources submodule should be imported as whole
2215
("from importlib.resources import files", ["COP002"]),
2316
# No violation: __future__ imports are allowed
2417
("from __future__ import annotations", []),
2518
# No violation: third-party imports are fine
2619
("from third_party import widget", []),
27-
# COP001: Importing more than two names from third party (but settings exempt)
28-
("from my_project.settings import A, B, C", []),
2920
# No violation: collections.abc is whitelisted
3021
("from collections.abc import AsyncIterator", []),
31-
# No violation: Multiple imports from stdlib subpackage
32-
("from importlib import resources, simple, util", []),
33-
# No violation: When __all__ is defined, more than two imports are allowed
34-
("__all__ = ['a', 'b', 'c']\nfrom x import a, b, c", []),
3522
# COP002: TypedDict should be imported from typing module, not via from import
3623
(
3724
"from typing import TypedDict, NotRequired\n\n"
@@ -58,7 +45,31 @@
5845
),
5946
],
6047
)
61-
def test_import_validations(input_source: str, expected_output: list[str]) -> None:
48+
def test_import_stdlib_validations(input_source: str, expected_output: list[str]) -> None:
49+
assert sorted(
50+
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
51+
) == sorted(expected_output)
52+
53+
@pytest.mark.skip("disabled")
54+
@pytest.mark.parametrize(
55+
("input_source", "expected_output"),
56+
[
57+
# COP001: Use module import when importing more than two names
58+
("from x import a, b, c", ["COP001"]),
59+
# COP001: Importing more than two names from third party (but settings exempt)
60+
("from my_project.settings import A, B, C", []),
61+
# No violation: importlib resources submodules are allowed
62+
("from importlib import resources", []),
63+
("from importlib import metadata", []),
64+
# No violation: unittest mock is allowed
65+
("from unittest import mock", []),
66+
# No violation: Multiple imports from stdlib subpackage
67+
("from importlib import resources, simple, util", []),
68+
# No violation: When __all__ is defined, more than two imports are allowed
69+
("__all__ = ['a', 'b', 'c']\nfrom x import a, b, c", []),
70+
],
71+
)
72+
def test_import_many_names_validations(input_source: str, expected_output: list[str]) -> None:
6273
assert sorted(
6374
[item[2].split(" ")[0] for item in CommunityOfPythonFlake8Plugin(ast.parse(input_source)).run()] # noqa: COP011
6475
) == sorted(expected_output)

0 commit comments

Comments
 (0)