@@ -1356,6 +1356,163 @@ def test_titled_imports() -> None:
1356
1356
)
1357
1357
1358
1358
1359
+ def test_footered_imports () -> None :
1360
+ """Tests setting both custom titles and footers to import sections."""
1361
+ test_input = (
1362
+ "import sys\n "
1363
+ "import unicodedata\n "
1364
+ "import statistics\n "
1365
+ "import os\n "
1366
+ "import myproject.test\n "
1367
+ "import django.settings"
1368
+ )
1369
+ test_output = isort .code (
1370
+ code = test_input ,
1371
+ known_first_party = ["myproject" ],
1372
+ import_footer_stdlib = "Standard Library End" ,
1373
+ import_footer_firstparty = "My Stuff End" ,
1374
+ )
1375
+ assert test_output == (
1376
+ "import os\n "
1377
+ "import statistics\n "
1378
+ "import sys\n "
1379
+ "import unicodedata\n "
1380
+ "\n "
1381
+ "# Standard Library End\n "
1382
+ "\n "
1383
+ "import django.settings\n "
1384
+ "\n "
1385
+ "import myproject.test\n "
1386
+ "\n "
1387
+ "# My Stuff End\n "
1388
+ )
1389
+ test_second_run = isort .code (
1390
+ code = test_output ,
1391
+ known_first_party = ["myproject" ],
1392
+ import_footer_stdlib = "Standard Library End" ,
1393
+ import_footer_firstparty = "My Stuff End" ,
1394
+ )
1395
+ assert test_second_run == test_output
1396
+
1397
+ test_input_lines_down = (
1398
+ "# comment 1\n "
1399
+ "import django.settings\n "
1400
+ "\n "
1401
+ "import sys\n "
1402
+ "import unicodedata\n "
1403
+ "import statistics\n "
1404
+ "import os\n "
1405
+ "import myproject.test\n "
1406
+ "\n "
1407
+ "# Standard Library End\n "
1408
+ )
1409
+ test_output_lines_down = isort .code (
1410
+ code = test_input_lines_down ,
1411
+ known_first_party = ["myproject" ],
1412
+ import_footer_stdlib = "Standard Library End" ,
1413
+ import_footer_firstparty = "My Stuff End" ,
1414
+ )
1415
+ assert test_output_lines_down == (
1416
+ "# comment 1\n "
1417
+ "import os\n "
1418
+ "import statistics\n "
1419
+ "import sys\n "
1420
+ "import unicodedata\n "
1421
+ "\n "
1422
+ "# Standard Library End\n "
1423
+ "\n "
1424
+ "import django.settings\n "
1425
+ "\n "
1426
+ "import myproject.test\n "
1427
+ "\n "
1428
+ "# My Stuff End\n "
1429
+ )
1430
+
1431
+
1432
+ def test_titled_and_footered_imports () -> None :
1433
+ """Tests setting custom footers to import sections."""
1434
+ test_input = (
1435
+ "import sys\n "
1436
+ "import unicodedata\n "
1437
+ "import statistics\n "
1438
+ "import os\n "
1439
+ "import myproject.test\n "
1440
+ "import django.settings"
1441
+ )
1442
+ test_output = isort .code (
1443
+ code = test_input ,
1444
+ known_first_party = ["myproject" ],
1445
+ import_heading_stdlib = "Standard Library" ,
1446
+ import_heading_firstparty = "My Stuff" ,
1447
+ import_footer_stdlib = "Standard Library End" ,
1448
+ import_footer_firstparty = "My Stuff End" ,
1449
+ )
1450
+ assert test_output == (
1451
+ "# Standard Library\n "
1452
+ "import os\n "
1453
+ "import statistics\n "
1454
+ "import sys\n "
1455
+ "import unicodedata\n "
1456
+ "\n "
1457
+ "# Standard Library End\n "
1458
+ "\n "
1459
+ "import django.settings\n "
1460
+ "\n "
1461
+ "# My Stuff\n "
1462
+ "import myproject.test\n "
1463
+ "\n "
1464
+ "# My Stuff End\n "
1465
+ )
1466
+ test_second_run = isort .code (
1467
+ code = test_output ,
1468
+ known_first_party = ["myproject" ],
1469
+ import_heading_stdlib = "Standard Library" ,
1470
+ import_heading_firstparty = "My Stuff" ,
1471
+ import_footer_stdlib = "Standard Library End" ,
1472
+ import_footer_firstparty = "My Stuff End" ,
1473
+ )
1474
+ assert test_second_run == test_output
1475
+
1476
+ test_input_lines_down = (
1477
+ "# comment 1\n "
1478
+ "import django.settings\n "
1479
+ "\n "
1480
+ "# Standard Library\n "
1481
+ "import sys\n "
1482
+ "import unicodedata\n "
1483
+ "import statistics\n "
1484
+ "import os\n "
1485
+ "import myproject.test\n "
1486
+ "\n "
1487
+ "# Standard Library End\n "
1488
+ )
1489
+ test_output_lines_down = isort .code (
1490
+ code = test_input_lines_down ,
1491
+ known_first_party = ["myproject" ],
1492
+ import_heading_stdlib = "Standard Library" ,
1493
+ import_heading_firstparty = "My Stuff" ,
1494
+ import_footer_stdlib = "Standard Library End" ,
1495
+ import_footer_firstparty = "My Stuff End" ,
1496
+ )
1497
+ assert test_output_lines_down == (
1498
+ "# comment 1\n "
1499
+ "# Standard Library\n "
1500
+ "import os\n "
1501
+ "import statistics\n "
1502
+ "import sys\n "
1503
+ "import unicodedata\n "
1504
+ "\n "
1505
+ "# Standard Library End\n "
1506
+ "\n "
1507
+ "import django.settings\n "
1508
+ "\n "
1509
+ "# My Stuff\n "
1510
+ "import myproject.test\n "
1511
+ "\n "
1512
+ "# My Stuff End\n "
1513
+ )
1514
+
1515
+
1359
1516
def test_balanced_wrapping () -> None :
1360
1517
"""Tests balanced wrapping mode, where the length of individual lines maintain width."""
1361
1518
test_input = (
0 commit comments