@@ -1266,8 +1266,6 @@ def test_force_single_line_imports_and_sort_within_sections() -> None:
1266
1266
"from third_party import lib_d\n "
1267
1267
)
1268
1268
1269
- # Ensure force_sort_within_sections can work with length sort
1270
- # See: https://github.com/pycqa/isort/issues/1038
1271
1269
test_input = """import sympy
1272
1270
import numpy as np
1273
1271
import pandas as pd
@@ -1280,21 +1278,59 @@ def test_force_single_line_imports_and_sort_within_sections() -> None:
1280
1278
1281
1279
def test_titled_imports () -> None :
1282
1280
"""Tests setting custom titled/commented import sections."""
1283
- test_input = (
1281
+ # test_input = (
1282
+ # "import sys\n"
1283
+ # "import unicodedata\n"
1284
+ # "import statistics\n"
1285
+ # "import os\n"
1286
+ # "import myproject.test\n"
1287
+ # "import django.settings"
1288
+ # )
1289
+ # test_output = isort.code(
1290
+ # code=test_input,
1291
+ # known_first_party=["myproject"],
1292
+ # import_heading_stdlib="Standard Library",
1293
+ # import_heading_firstparty="My Stuff",
1294
+ # )
1295
+ # assert test_output == (
1296
+ # "# Standard Library\n"
1297
+ # "import os\n"
1298
+ # "import statistics\n"
1299
+ # "import sys\n"
1300
+ # "import unicodedata\n"
1301
+ # "\n"
1302
+ # "import django.settings\n"
1303
+ # "\n"
1304
+ # "# My Stuff\n"
1305
+ # "import myproject.test\n"
1306
+ # )
1307
+ # test_second_run = isort.code(
1308
+ # code=test_output,
1309
+ # known_first_party=["myproject"],
1310
+ # import_heading_stdlib="Standard Library",
1311
+ # import_heading_firstparty="My Stuff",
1312
+ # )
1313
+ # assert test_second_run == test_output
1314
+
1315
+ test_input_lines_down = (
1316
+ "# comment 1\n "
1317
+ "import django.settings\n "
1318
+ "\n "
1319
+ "# Standard Library\n "
1284
1320
"import sys\n "
1285
1321
"import unicodedata\n "
1286
1322
"import statistics\n "
1287
1323
"import os\n "
1288
1324
"import myproject.test\n "
1289
- "import django.settings"
1290
1325
)
1291
- test_output = isort .code (
1292
- code = test_input ,
1326
+ test_output_lines_down = isort .code (
1327
+ code = test_input_lines_down ,
1293
1328
known_first_party = ["myproject" ],
1294
1329
import_heading_stdlib = "Standard Library" ,
1295
1330
import_heading_firstparty = "My Stuff" ,
1296
1331
)
1297
- assert test_output == (
1332
+ assert test_output_lines_down == (
1333
+ "# comment 1\n "
1298
1334
"# Standard Library\n "
1299
1335
"import os\n "
1300
1336
"import statistics\n "
@@ -1306,13 +1342,6 @@ def test_titled_imports() -> None:
1306
1342
"# My Stuff\n "
1307
1343
"import myproject.test\n "
1308
1344
)
1309
- test_second_run = isort .code (
1310
- code = test_output ,
1311
- known_first_party = ["myproject" ],
1312
- import_heading_stdlib = "Standard Library" ,
1313
- import_heading_firstparty = "My Stuff" ,
1314
- )
1315
- assert test_second_run == test_output
1316
1345
1317
1346
1318
1347
def test_balanced_wrapping () -> None :
@@ -1501,6 +1530,7 @@ def test_combined_from_and_as_imports() -> None:
1501
1530
"from translate.storage.placeables import general, parse as rich_parse\n "
1502
1531
)
1503
1532
assert isort .code (test_input , combine_as_imports = True ) == test_input
1533
+ assert isort .code (test_input , combine_as_imports = True , only_sections = True ) == test_input
1504
1534
test_input = "import os \n import os as _os"
1505
1535
test_output = "import os\n import os as _os\n "
1506
1536
assert isort .code (test_input ) == test_output
@@ -4804,6 +4834,23 @@ def test_noqa_issue_1065() -> None:
4804
4834
"""
4805
4835
assert isort .code (test_input , line_length = 100 ) == expected_output
4806
4836
4837
+ test_input_2 = """
4838
+ #
4839
+ # USER SIGNALS
4840
+ #
4841
+
4842
+ from flask_login import user_logged_in, user_logged_out # noqa
4843
+
4844
+ from flask_security.signals import (
4845
+ password_changed as user_reset_password, # noqa
4846
+ user_confirmed, # noqa
4847
+ user_registered, # noqa
4848
+ )
4849
+
4850
+ from flask_principal import identity_changed as user_identity_changed # noqa
4851
+ """
4852
+ assert isort .code (test_input_2 , line_length = 100 ) == expected_output
4853
+
4807
4854
4808
4855
def test_single_line_exclusions ():
4809
4856
test_input = """
0 commit comments