Skip to content

Commit 3808b70

Browse files
hansu650DanielNoord
authored andcommitted
Keep CRLF regression cases beside existing check-mode tests
1 parent 3202ce8 commit 3808b70

1 file changed

Lines changed: 55 additions & 55 deletions

File tree

‎tests/unit/test_regressions.py‎

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -919,61 +919,6 @@ def test_isort_float_to_top_respects_isort_off_with_crlf_issue_2528():
919919
)
920920

921921

922-
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
923-
@pytest.mark.parametrize(
924-
"boundary",
925-
[
926-
"# isort: split\n",
927-
"import z # isort: split\n",
928-
"# isort: off\nimport z\nimport a\n# isort: on\n",
929-
],
930-
)
931-
def test_float_to_top_check_accepts_unchanged_sections_issue_2681(line_ending, boundary):
932-
source = ("import os\n\n" + boundary + "\nimport sys\n").replace("\n", line_ending)
933-
934-
assert isort.code(source, float_to_top=True) == source
935-
assert isort.check_code(source, float_to_top=True, show_diff=True)
936-
937-
938-
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
939-
@pytest.mark.parametrize("blank_lines", [0, 1, 3])
940-
def test_float_to_top_preserves_boundary_spacing_issue_2681(line_ending, blank_lines):
941-
source = ("import os\n" + "\n" * blank_lines + "# isort: split\n").replace("\n", line_ending)
942-
result = _float_to_top(StringIO(source), [], isort.Config(float_to_top=True), "py")
943-
944-
assert result.input_stream.read() == source
945-
assert not result.made_changes
946-
947-
948-
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
949-
def test_float_to_top_check_detects_unsorted_sections_issue_2681(line_ending):
950-
source = "import sys\nimport os\n\n# isort: split\n\nimport a\n".replace("\n", line_ending)
951-
expected = "import os\nimport sys\n\n# isort: split\n\nimport a\n".replace("\n", line_ending)
952-
953-
assert not isort.check_code(source, float_to_top=True)
954-
assert isort.code(source, float_to_top=True) == expected
955-
assert isort.check_code(expected, float_to_top=True)
956-
957-
958-
@pytest.mark.parametrize("configured_ending", ["\n", "\r\n"])
959-
def test_float_to_top_configured_line_ending_issue_2681(configured_ending):
960-
source = "import os\r\n\r\n# isort: split\r\n\r\nimport sys\r\n"
961-
expected = source.replace("\r\n", configured_ending)
962-
result = isort.code(source, float_to_top=True, line_ending=configured_ending)
963-
964-
assert result == expected
965-
assert isort.check_code(result, float_to_top=True, line_ending=configured_ending)
966-
967-
968-
def test_float_to_top_cli_check_accepts_crlf_issue_2681(tmp_path):
969-
path = tmp_path / "example.py"
970-
source = b"import os\r\n\r\n# isort: split\r\n\r\nimport sys\r\n"
971-
path.write_bytes(source)
972-
973-
main(["--float-to-top", "--check-only", str(path)])
974-
assert path.read_bytes() == source
975-
976-
977922
def test_isort_doesnt_float_to_top_correctly_when_imports_not_at_top_issue_1382():
978923
"""isort should float existing imports to the top, if they are currently below the top.
979924
See: https://github.com/PyCQA/isort/issues/1382
@@ -2082,6 +2027,61 @@ def test_check_code_should_not_false_positive_with_float_to_top_and_add_imports(
20822027
)
20832028

20842029

2030+
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
2031+
@pytest.mark.parametrize(
2032+
"boundary",
2033+
[
2034+
"# isort: split\n",
2035+
"import z # isort: split\n",
2036+
"# isort: off\nimport z\nimport a\n# isort: on\n",
2037+
],
2038+
)
2039+
def test_float_to_top_check_accepts_unchanged_sections_issue_2681(line_ending, boundary):
2040+
source = ("import os\n\n" + boundary + "\nimport sys\n").replace("\n", line_ending)
2041+
2042+
assert isort.code(source, float_to_top=True) == source
2043+
assert isort.check_code(source, float_to_top=True, show_diff=True)
2044+
2045+
2046+
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
2047+
@pytest.mark.parametrize("blank_lines", [0, 1, 3])
2048+
def test_float_to_top_preserves_boundary_spacing_issue_2681(line_ending, blank_lines):
2049+
source = ("import os\n" + "\n" * blank_lines + "# isort: split\n").replace("\n", line_ending)
2050+
result = _float_to_top(StringIO(source), [], isort.Config(float_to_top=True), "py")
2051+
2052+
assert result.input_stream.read() == source
2053+
assert not result.made_changes
2054+
2055+
2056+
@pytest.mark.parametrize("line_ending", ["\n", "\r\n"])
2057+
def test_float_to_top_check_detects_unsorted_sections_issue_2681(line_ending):
2058+
source = "import sys\nimport os\n\n# isort: split\n\nimport a\n".replace("\n", line_ending)
2059+
expected = "import os\nimport sys\n\n# isort: split\n\nimport a\n".replace("\n", line_ending)
2060+
2061+
assert not isort.check_code(source, float_to_top=True)
2062+
assert isort.code(source, float_to_top=True) == expected
2063+
assert isort.check_code(expected, float_to_top=True)
2064+
2065+
2066+
@pytest.mark.parametrize("configured_ending", ["\n", "\r\n"])
2067+
def test_float_to_top_configured_line_ending_issue_2681(configured_ending):
2068+
source = "import os\r\n\r\n# isort: split\r\n\r\nimport sys\r\n"
2069+
expected = source.replace("\r\n", configured_ending)
2070+
result = isort.code(source, float_to_top=True, line_ending=configured_ending)
2071+
2072+
assert result == expected
2073+
assert isort.check_code(result, float_to_top=True, line_ending=configured_ending)
2074+
2075+
2076+
def test_float_to_top_cli_check_accepts_crlf_issue_2681(tmp_path):
2077+
path = tmp_path / "example.py"
2078+
source = b"import os\r\n\r\n# isort: split\r\n\r\nimport sys\r\n"
2079+
path.write_bytes(source)
2080+
2081+
main(["--float-to-top", "--check-only", str(path)])
2082+
assert path.read_bytes() == source
2083+
2084+
20852085
def test_unrecoverable_exception_on_valid_input_ending_with_backslash_issue_1893():
20862086
"""Ensure isort doesn't raise an IndexError on valid input ending with a backslash
20872087
without a trailing newline, as was the case in issue #1893:

0 commit comments

Comments
 (0)