Skip to content

Commit a7a9282

Browse files
CopilotDanielNoord
andauthored
Apply PR feedback by removing and simplifying lazy import tests
Agent-Logs-Url: https://github.com/PyCQA/isort/sessions/598e293a-0a92-45ab-9a4e-089fc26c97b4 Co-authored-by: DanielNoord <13665637+DanielNoord@users.noreply.github.com>
1 parent dcdfa3c commit a7a9282

1 file changed

Lines changed: 9 additions & 66 deletions

File tree

tests/unit/test_lazy_imports.py

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import isort
21
from isort import Config, parse
32

43
from .utils import isort_test
@@ -95,19 +94,6 @@ def test_lazy_imports_appear_after_eager_in_each_section_independently():
9594
isort_test(unsorted, expected, known_third_party=["requests"])
9695

9796

98-
def test_only_lazy_imports_in_section():
99-
"""A section that contains *only* lazy imports is formatted correctly."""
100-
isort_test("lazy import ast\nlazy import os\n", "lazy import ast\nlazy import os\n")
101-
102-
103-
def test_only_lazy_from_imports():
104-
"""A section with only lazy from-imports is formatted correctly."""
105-
isort_test(
106-
"lazy from dataclasses import dataclass\nlazy from pathlib import Path\n",
107-
"lazy from dataclasses import dataclass\nlazy from pathlib import Path\n",
108-
)
109-
110-
11197
def test_lazy_import_with_alias():
11298
"""``lazy import X as Y`` is supported and sorted correctly."""
11399
isort_test(
@@ -122,47 +108,6 @@ def test_lazy_from_import_multiple_names():
122108
isort_test("lazy from typing import List, Dict\n", "lazy from typing import Dict, List\n")
123109

124110

125-
def test_idempotency_mixed_eager_and_lazy():
126-
"""Running isort twice on sorted output must not change anything."""
127-
isort_test(
128-
"lazy from dataclasses import dataclass\nimport json\nlazy import ast\nimport os\n",
129-
"import json\nimport os\nlazy import ast\nlazy from dataclasses import dataclass\n",
130-
)
131-
132-
133-
def test_idempotency_only_lazy():
134-
"""Idempotency with a file that contains only lazy imports."""
135-
isort_test("lazy import shutil\nlazy import ast\n", "lazy import ast\nlazy import shutil\n")
136-
137-
138-
def test_check_code_sorted():
139-
"""check_code returns True when lazy imports are already sorted."""
140-
assert isort.check_code(
141-
"import os\nlazy import ast\n",
142-
show_diff=False,
143-
)
144-
145-
146-
def test_check_code_unsorted():
147-
"""check_code returns False when lazy imports are not sorted."""
148-
assert not isort.check_code(
149-
"lazy import ast\nimport os\n",
150-
show_diff=False,
151-
)
152-
153-
154-
def test_lazy_and_eager_from_same_module_in_section():
155-
"""Both eager and lazy imports from the same module are retained."""
156-
# This is an unusual pattern but should not cause errors.
157-
result = isort.code("from pathlib import Path\nlazy from pathlib import PurePath\n")
158-
assert "from pathlib import Path" in result
159-
assert "lazy from pathlib import PurePath" in result
160-
# eager must come before lazy
161-
assert result.index("from pathlib import Path") < result.index(
162-
"lazy from pathlib import PurePath"
163-
)
164-
165-
166111
def test_no_sections_mode_with_lazy_imports():
167112
"""lazy imports are supported in no_sections mode."""
168113
isort_test(
@@ -173,23 +118,21 @@ def test_no_sections_mode_with_lazy_imports():
173118

174119

175120
def test_from_first_option_respected_for_lazy():
176-
"""When from_first=True, lazy from imports precede lazy straight imports."""
121+
"""When from_first=True, lazy from imports precede lazy straight imports but appear before eager imports."""
177122
isort_test(
178-
"lazy import ast\nlazy from dataclasses import dataclass\n",
179-
"lazy from dataclasses import dataclass\nlazy import ast\n",
123+
"import pathlib\nlazy import ast\nlazy from dataclasses import dataclass\n",
124+
"import pathlib\nlazy from dataclasses import dataclass\nlazy import ast\n",
180125
from_first=True,
181126
)
182127

183128

184129
def test_force_sort_within_sections_applies_to_lazy():
185-
"""With force_sort_within_sections=True, lazy straight and from imports are interleaved
186-
and sorted together by module name instead of straight-before-from."""
187-
# Without force_sort_within_sections the default is straight-before-from:
188-
# lazy import zlib
189-
# lazy from ast import parse
190-
# With force_sort_within_sections they are sorted together by module name:
191-
# lazy from ast import parse (key: "lazy from ast ...")
192-
# lazy import zlib (key: "lazy import zlib")
130+
"""force_sort_within_sections toggles lazy import ordering behavior."""
131+
isort_test(
132+
"lazy import zlib\nlazy from ast import parse\n",
133+
"lazy import zlib\nlazy from ast import parse\n",
134+
force_sort_within_sections=False,
135+
)
193136
isort_test(
194137
"lazy import zlib\nlazy from ast import parse\n",
195138
"lazy from ast import parse\nlazy import zlib\n",

0 commit comments

Comments
 (0)