summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Edmund Crosley <timothy.crosley@gmail.com>2019-04-05 20:45:54 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2019-04-05 21:22:34 -0700
commit3a4f531ef6ca798fcc1b5994e82e181580f995bd (patch)
treee8ec15f4886230541136ad7faea7d2b55b8206c8
parent7d8244fb16abf8497bf3d15fb4fce8768a58f4c4 (diff)
downloadisort-3a4f531ef6ca798fcc1b5994e82e181580f995bd.tar.gz
Merge pull request #917 from timothycrosley/feature/fix-issue-916
Feature/fix issue 916
-rw-r--r--isort/isort.py2
-rw-r--r--test_isort.py19
2 files changed, 20 insertions, 1 deletions
diff --git a/isort/isort.py b/isort/isort.py
index adc64ab3..7ae539d5 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -829,7 +829,7 @@ class SortImports(object):
self._in_top_comment = True
return True
elif self._in_top_comment:
- if not line.startswith("#"):
+ if not line.startswith("#") or line in self._section_comments:
self._in_top_comment = False
self._first_comment_index_end = self.index - 1
diff --git a/test_isort.py b/test_isort.py
index c4d3b4e5..8f152ddf 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2926,3 +2926,22 @@ def test_standard_library_deprecates_user_issue_778():
'\n'
'import user\n')
assert SortImports(file_contents=test_input).output == test_input
+
+
+def test_failing_file_check_916():
+ test_input = ('#!/usr/bin/env python\n'
+ '# -*- coding: utf-8 -*-\n'
+ 'from __future__ import unicode_literals\n')
+ expected_output = ('#!/usr/bin/env python\n'
+ '# -*- coding: utf-8 -*-\n'
+ '# FUTURE\n'
+ 'from __future__ import unicode_literals\n')
+ settings = {'known_future_library': 'future',
+ 'import_heading_future': 'FUTURE',
+ 'sections': ['FUTURE', 'STDLIB', 'NORDIGEN', 'FIRSTPARTY', 'THIRDPARTY', 'LOCALFOLDER'],
+ 'indent': ' ',
+ 'multi_line_output': 3,
+ 'lines_after_imports': 2}
+ assert SortImports(file_contents=test_input, **settings).output == expected_output
+ assert SortImports(file_contents=expected_output, **settings).output == expected_output
+ assert not SortImports(file_contents=expected_output, check=True, **settings).incorrectly_sorted