Skip to content

Commit

Permalink
Formatting with black + isort
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Sep 3, 2020
1 parent e2b2f8d commit 2c84fc2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
8 changes: 7 additions & 1 deletion isort/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte
if skipping_line:
out_lines.append(line)
continue
elif config.float_to_top and import_index == -1 and line and not in_quote and not line.strip().startswith("#"):
elif (
config.float_to_top
and import_index == -1
and line
and not in_quote
and not line.strip().startswith("#")
):
import_index = index - 1
while import_index and not in_lines[import_index - 1]:
import_index -= 1
Expand Down
63 changes: 46 additions & 17 deletions tests/unit/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,20 @@ 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('''
assert (
isort.code(
"""
def foo():
pass
import a
def bar():
pass
''',
float_to_top=True) == '''import a
""",
float_to_top=True,
)
== """import a
def foo():
Expand All @@ -738,9 +742,12 @@ def foo():
def bar():
pass
'''
"""
)

assert isort.code('''
assert (
isort.code(
"""
Expand All @@ -754,8 +761,10 @@ def foo():
def bar():
pass
''',
float_to_top=True) == '''import a
""",
float_to_top=True,
)
== """import a
def foo():
Expand All @@ -764,9 +773,12 @@ def foo():
def bar():
pass
'''
"""
)

assert isort.code('''"""My comment
assert (
isort.code(
'''"""My comment
"""
Expand All @@ -778,7 +790,9 @@ def foo():
def bar():
pass
''',
float_to_top=True) == '''"""My comment
float_to_top=True,
)
== '''"""My comment
"""
Expand All @@ -792,9 +806,11 @@ def foo():
def bar():
pass
'''
)


assert isort.code('''
assert (
isort.code(
'''
"""My comment
Expand All @@ -807,7 +823,9 @@ def foo():
def bar():
pass
''',
float_to_top=True) == '''
float_to_top=True,
)
== '''
"""My comment
Expand All @@ -822,8 +840,11 @@ def foo():
def bar():
pass
'''
)

assert isort.code('''#!/bin/bash
assert (
isort.code(
'''#!/bin/bash
"""My comment
Expand All @@ -836,7 +857,9 @@ def foo():
def bar():
pass
''',
float_to_top=True) == '''#!/bin/bash
float_to_top=True,
)
== '''#!/bin/bash
"""My comment
Expand All @@ -851,8 +874,11 @@ def foo():
def bar():
pass
'''
)

assert isort.code('''#!/bin/bash
assert (
isort.code(
'''#!/bin/bash
"""My comment
Expand All @@ -866,7 +892,9 @@ def foo():
def bar():
pass
''',
float_to_top=True) == '''#!/bin/bash
float_to_top=True,
)
== '''#!/bin/bash
"""My comment
Expand All @@ -882,3 +910,4 @@ def foo():
def bar():
pass
'''
)
9 changes: 3 additions & 6 deletions tests/unit/test_ticketed_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def my_function_2():
""",
float_to_top=True,
)
== """
import os
== """import os
import sys
Expand Down Expand Up @@ -91,8 +90,7 @@ def my_function_2():
""",
float_to_top=True,
)
== """
import os
== """import os
def my_function_1():
Expand Down Expand Up @@ -133,8 +131,7 @@ def my_function_2():
""",
float_to_top=True,
)
== """
import os
== """import os
def my_function_1():
Expand Down

0 comments on commit 2c84fc2

Please sign in to comment.