summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Szabo <szabtam@gmail.com>2020-10-03 10:27:30 +0300
committerTamas Szabo <szabtam@gmail.com>2020-10-03 10:27:30 +0300
commita397eb698f245dd6b46c47e426a4f80927867446 (patch)
tree3e86f65de6d79bd14dcd0895a76eb15d1c3356ed
parentd7f0997f902d42a5b676a205c1dd67d37a735800 (diff)
downloadisort-characterization-test-float-to-top-in-sort-on-off.tar.gz
Adds characterization tests for float_to_top and on/off.characterization-test-float-to-top-in-sort-on-off
-rw-r--r--tests/unit/test_regressions.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py
index 5dc2fc81..75759522 100644
--- a/tests/unit/test_regressions.py
+++ b/tests/unit/test_regressions.py
@@ -716,6 +716,81 @@ import os
)
+def test_isort_float_to_top_with_sort_on_off_tests():
+ """Characterization test for current behaviour of float-to-top on isort: on/off sections.
+ - imports in isort:off sections stay where they are
+ - imports in isort:on sections float up, but to the top of the isort:on section (not the
+ top of the file)"""
+ assert (
+ isort.code(
+ """
+def foo():
+ pass
+
+import a
+
+# isort: off
+import stays_in_section
+
+x = 1
+
+import stays_in_place
+
+# isort: on
+
+def bar():
+ pass
+
+import floats_to_top_of_section
+
+def baz():
+ pass
+""",
+ float_to_top=True,
+ )
+ == """import a
+
+
+def foo():
+ pass
+
+# isort: off
+import stays_in_section
+
+x = 1
+
+import stays_in_place
+
+# isort: on
+import floats_to_top_of_section
+
+
+def bar():
+ pass
+
+
+def baz():
+ pass
+"""
+ )
+
+ to_sort = """# isort: off
+
+def foo():
+ pass
+
+import stays_in_place
+import no_float_to_to_top
+import no_ordering
+
+def bar():
+ pass
+"""
+
+ # No changes if isort is off
+ assert isort.code(to_sort, float_to_top=True) == to_sort
+
+
def test_isort_doesnt_float_to_top_correctly_when_imports_not_at_top_issue_1382():
"""isort should float existing imports to the top, if they are currently below the top.
See: https://github.com/PyCQA/isort/issues/1382