Repository: timothycrosley/isort (python)

Issue:
4.3.16 failing file check after isort
test.py

Before isort ->
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
```

After isort ->
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FUTURE
from __future__ import unicode_literals
```

isort -c test.py ->
```
ERROR: bla-bla-bla/test.py Imports are incorrectly sorted.
```

isort -df test.py ->
```
--- bla-bla-bla/test.py:before 2019-03-29 21:21:31.371673
+++ bla-bla-bla/test.py:after  2019-03-30 11:43:43.791501
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 # FUTURE
+# FUTURE
 from __future__ import unicode_literals
```

Here's settings:
```
[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
```

Is this a bug or I'm doing something wrong and I can be changed thru settings?
Thanks.

Pull request:
Feature/fix issue 916
Fixes #916 

Patch:
diff --git a/isort/isort.py b/isort/isort.py
index 5757c009..7609648e 100644
--- a/isort/isort.py
+++ b/isort/isort.py
@@ -884,7 +884,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
 


Test patch:
diff --git a/test_isort.py b/test_isort.py
index a729139b..7c42e84c 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -2961,3 +2961,22 @@ def test_settings_path_skip_issue_909(tmpdir):
     os.chdir(str(test_run_directory))
 
     assert b'skipped 2' in results.lower()
+
+
+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