summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorParnassius <Parnassius@users.noreply.github.com>2021-09-30 11:53:08 +0200
committerParnassius <Parnassius@users.noreply.github.com>2021-09-30 15:31:05 +0200
commit146e01bc64765149d270485086e06a37e8ab6e03 (patch)
treecd4c30533feed2cbf120503b06cdf7223ba770a0 /tests
parent995e016b9d888fea02bedeb5be8ea7f01b694b58 (diff)
downloadisort-146e01bc64765149d270485086e06a37e8ab6e03.tar.gz
Add an option to set a footer for every import section
Closes #1733
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_setting_combinations.py4
-rw-r--r--tests/unit/test_isort.py157
2 files changed, 161 insertions, 0 deletions
diff --git a/tests/integration/test_setting_combinations.py b/tests/integration/test_setting_combinations.py
index d2159fd3..aca9c9ca 100644
--- a/tests/integration/test_setting_combinations.py
+++ b/tests/integration/test_setting_combinations.py
@@ -553,6 +553,7 @@ else: # 2.x
),
default_section="THIRDPARTY",
import_headings={},
+ import_footers={},
balanced_wrapping=False,
use_parentheses=True,
order_by_type=True,
@@ -859,6 +860,7 @@ else: # 2.x
"single_line_exclusions": (),
"default_section": "THIRDPARTY",
"import_headings": {},
+ "import_footers": {},
"balanced_wrapping": False,
"use_parentheses": False,
"order_by_type": True,
@@ -1414,6 +1416,7 @@ def test_isort_is_idempotent(config: isort.Config, disregard_skip: bool) -> None
),
default_section="THIRDPARTY",
import_headings={},
+ import_footers={},
balanced_wrapping=False,
use_parentheses=True,
order_by_type=True,
@@ -1720,6 +1723,7 @@ def test_isort_is_idempotent(config: isort.Config, disregard_skip: bool) -> None
"single_line_exclusions": (),
"default_section": "THIRDPARTY",
"import_headings": {},
+ "import_footers": {},
"balanced_wrapping": False,
"use_parentheses": False,
"order_by_type": True,
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py
index bf22d34b..a1013884 100644
--- a/tests/unit/test_isort.py
+++ b/tests/unit/test_isort.py
@@ -1356,6 +1356,163 @@ def test_titled_imports() -> None:
)
+def test_footered_imports() -> None:
+ """Tests setting both custom titles and footers to import sections."""
+ test_input = (
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "import django.settings"
+ )
+ test_output = isort.code(
+ code=test_input,
+ known_first_party=["myproject"],
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_output == (
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "# Standard Library End\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "import myproject.test\n"
+ "\n"
+ "# My Stuff End\n"
+ )
+ test_second_run = isort.code(
+ code=test_output,
+ known_first_party=["myproject"],
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_second_run == test_output
+
+ test_input_lines_down = (
+ "# comment 1\n"
+ "import django.settings\n"
+ "\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "\n"
+ "# Standard Library End\n"
+ )
+ test_output_lines_down = isort.code(
+ code=test_input_lines_down,
+ known_first_party=["myproject"],
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_output_lines_down == (
+ "# comment 1\n"
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "# Standard Library End\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "import myproject.test\n"
+ "\n"
+ "# My Stuff End\n"
+ )
+
+
+def test_titled_and_footered_imports() -> None:
+ """Tests setting custom footers to import sections."""
+ test_input = (
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "import django.settings"
+ )
+ test_output = isort.code(
+ code=test_input,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_output == (
+ "# Standard Library\n"
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "# Standard Library End\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "# My Stuff\n"
+ "import myproject.test\n"
+ "\n"
+ "# My Stuff End\n"
+ )
+ test_second_run = isort.code(
+ code=test_output,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_second_run == test_output
+
+ test_input_lines_down = (
+ "# comment 1\n"
+ "import django.settings\n"
+ "\n"
+ "# Standard Library\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "\n"
+ "# Standard Library End\n"
+ )
+ test_output_lines_down = isort.code(
+ code=test_input_lines_down,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
+ import_footer_stdlib="Standard Library End",
+ import_footer_firstparty="My Stuff End",
+ )
+ assert test_output_lines_down == (
+ "# comment 1\n"
+ "# Standard Library\n"
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "# Standard Library End\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "# My Stuff\n"
+ "import myproject.test\n"
+ "\n"
+ "# My Stuff End\n"
+ )
+
+
def test_balanced_wrapping() -> None:
"""Tests balanced wrapping mode, where the length of individual lines maintain width."""
test_input = (