Skip to content

Commit

Permalink
Add test for desired float_to_top behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Sep 3, 2020
1 parent a935c17 commit 31f26da
Showing 1 changed file with 168 additions and 0 deletions.
168 changes: 168 additions & 0 deletions tests/unit/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,171 @@ def test_isort_doesnt_mangle_code_when_adding_imports_issue_1444():
import os
'''
)


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
"""
assert isort.code('''
def foo():
pass
import a
def bar():
pass
''',
float_to_top=True) == '''import a
def foo():
pass
def bar():
pass
'''

assert isort.code('''
def foo():
pass
import a
def bar():
pass
''',
float_to_top=True) == '''import a
def foo():
pass
def bar():
pass
'''

assert isort.code('''"""My comment
"""
def foo():
pass
import a
def bar():
pass
''',
float_to_top=True) == '''"""My comment
"""
import a
def foo():
pass
def bar():
pass
'''


assert isort.code('''
"""My comment
"""
def foo():
pass
import a
def bar():
pass
''',
float_to_top=True) == '''
"""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.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
'''

0 comments on commit 31f26da

Please sign in to comment.