diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-25 20:42:56 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-25 20:42:56 -0700 |
commit | 0f8eff147a1e6d6d1fa081e4738a97dd3c02e13d (patch) | |
tree | 252bb651b85ff3ed6529385f18bc82da133c0ed0 | |
parent | 4771e4392f77b604e9eae23d9ce8992e4e076aaf (diff) | |
download | isort-0f8eff147a1e6d6d1fa081e4738a97dd3c02e13d.tar.gz |
Add test case for #1499: single-line multi-line string comment confuses float-to-top
-rw-r--r-- | tests/unit/test_regressions.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py index 4869d444..5c609d20 100644 --- a/tests/unit/test_regressions.py +++ b/tests/unit/test_regressions.py @@ -1081,3 +1081,80 @@ def generator_function(): from \\ """ assert isort.check_code(raise_from_at_file_end_ignored, show_diff=True) + + +def test_isort_float_to_top_correctly_identifies_single_line_comments_1499(): + """Test to ensure isort correctly handles the case where float to top is used + to push imports to the top and the top comment is a multiline type but only + one line. + See: https://github.com/PyCQA/isort/issues/1499 + """ + assert ( + isort.code( + '''#!/bin/bash +"""My comment""" +def foo(): + pass + +import a + +def bar(): + pass +''', + float_to_top=True, + ) + == ( + '''#!/bin/bash +"""My comment""" +import a + + +def foo(): + pass + + +def bar(): + pass +''' + ) + ) + assert ( + isort.code( + """#!/bin/bash +'''My comment''' +def foo(): + pass + +import a + +def bar(): + pass +""", + float_to_top=True, + ) + == ( + """#!/bin/bash +'''My comment''' +import a + + +def foo(): + pass + + +def bar(): + pass +""" + ) + ) + + assert isort.check_code( + """#!/bin/bash +'''My comment''' +import a + +x = 1 +""", + float_to_top=True, + show_diff=True, + ) |