diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-12-23 04:38:32 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-12-23 04:38:32 -0800 |
commit | 29af5bd59536a670eb3de3b087cdd1e07f0f58dd (patch) | |
tree | 592322f3ccc170720155f70bc54904696dc93a94 | |
parent | 9c7668375f911b4da53f6eb1ab6287c65da7f720 (diff) | |
download | isort-29af5bd59536a670eb3de3b087cdd1e07f0f58dd.tar.gz |
Update tests to match updated behavior
-rw-r--r-- | isort/api.py | 6 | ||||
-rw-r--r-- | tests/test_isort.py | 18 |
2 files changed, 10 insertions, 14 deletions
diff --git a/isort/api.py b/isort/api.py index d9cfabeb..14602378 100644 --- a/isort/api.py +++ b/isort/api.py @@ -176,7 +176,11 @@ def sort_imports( line_separator = line[-1] stripped_line = line.strip() - if index == 0 and line.startswith("#") and stripped_line not in section_comments: + if ( + (index == 0 or (index == 1 and not contains_imports)) + and line.startswith("#") + and stripped_line not in section_comments + ): in_top_comment = True elif in_top_comment: if not line.startswith("#") or stripped_line in section_comments: diff --git a/tests/test_isort.py b/tests/test_isort.py index 8673ab46..d67bdcf7 100644 --- a/tests/test_isort.py +++ b/tests/test_isort.py @@ -778,14 +778,10 @@ def test_quotes_in_file() -> None: assert SortImports(file_contents=test_input).output == test_input test_input = "import os\n\n" '\'"""\'\n' "import foo\n" - assert SortImports(file_contents=test_input).output == ( - "import os\n\nimport foo\n\n" '\'"""\'\n' - ) + assert SortImports(file_contents=test_input).output == test_input - test_input = "import os\n\n" '"""Let us"""\n' "import foo\n" '"""okay?"""\n' - assert SortImports(file_contents=test_input).output == ( - 'import os\n\nimport foo\n\n"""Let us"""\n"""okay?"""\n' - ) + test_input = "import os\n\n" '"""Let us"""\n' "import foo\n\n" '"""okay?"""\n' + assert SortImports(file_contents=test_input).output == test_input test_input = "import os\n\n" '#"""\n' "import foo\n" '#"""' assert SortImports(file_contents=test_input).output == ( @@ -1201,7 +1197,7 @@ def test_smart_lines_after_import_section() -> None: " pass\n" ) - # ensure logic works with both style comments + # the same logic does not apply to doc strings test_input = ( "from a import b\n" '"""\n' @@ -1213,7 +1209,6 @@ def test_smart_lines_after_import_section() -> None: assert SortImports(file_contents=test_input).output == ( "from a import b\n" "\n" - "\n" '"""\n' " comment should be ignored\n" '"""\n' @@ -1631,9 +1626,8 @@ def test_place_comments() -> None: "\n" "# isort:imports-thirdparty\n" "# isort:imports-firstparty\n" - "print('code')\n" - "\n" "# isort:imports-stdlib\n" + "\n" ) expected_output = ( "\n# isort:imports-thirdparty\n" @@ -1642,8 +1636,6 @@ def test_place_comments() -> None: "# isort:imports-firstparty\n" "import myproject.test\n" "\n" - "print('code')\n" - "\n" "# isort:imports-stdlib\n" "import os\n" "import sys\n" |