From 77ea8dc4cfc71f7fb191ea383d842bdd59db777d Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 30 Mar 2019 23:15:30 -0700 Subject: Add initial test case --- test_isort.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test_isort.py b/test_isort.py index a729139b..5341fbad 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2961,3 +2961,20 @@ 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(test_input, **setting).output == expected_output -- cgit v1.2.1 From 2d0c62b8aaece05b11590874b1b3b5cdfd90d43d Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 2 Apr 2019 23:36:46 -0700 Subject: Fix test case --- test_isort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_isort.py b/test_isort.py index 5341fbad..21324376 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2977,4 +2977,4 @@ def test_failing_file_check_916(): 'indent': ' ', 'multi_line_output': 3, 'lines_after_imports': 2} - assert SortImports(test_input, **setting).output == expected_output + assert SortImports(test_input, **settings).output == expected_output -- cgit v1.2.1 From f53681f4a99a043e7c9c372eb622f5395fd2f009 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Wed, 3 Apr 2019 23:21:41 -0700 Subject: Fix test case --- test_isort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_isort.py b/test_isort.py index 21324376..44775c14 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2973,8 +2973,8 @@ def test_failing_file_check_916(): 'from __future__ import unicode_literals\n') settings = {'known_future_library': 'future', 'import_heading_future': 'FUTURE', - 'sections': 'FUTURE,STDLIB,NORDIGEN,FIRSTPARTY,THIRDPARTY,LOCALFOLDER', + 'sections': ['FUTURE', 'STDLIB', 'NORDIGEN', 'FIRSTPARTY', 'THIRDPARTY', 'LOCALFOLDER'], 'indent': ' ', 'multi_line_output': 3, 'lines_after_imports': 2} - assert SortImports(test_input, **settings).output == expected_output + assert SortImports(file_contents=test_input, **settings).output == expected_output -- cgit v1.2.1 From d0aba7f632a9f117fc10c03970e08c12b828a77a Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Wed, 3 Apr 2019 23:27:31 -0700 Subject: Add correctly failing test case for issue --- test_isort.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_isort.py b/test_isort.py index 44775c14..7c42e84c 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2978,3 +2978,5 @@ def test_failing_file_check_916(): '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 -- cgit v1.2.1 From cbf6ba7a1fcdf5ac7492adb2137bd646f9a27d81 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 4 Apr 2019 21:07:11 -0700 Subject: Fix issue #916 --- isort/isort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -- cgit v1.2.1