diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-01-14 23:20:58 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-01-14 23:20:58 -0800 |
commit | 63067802cedb570b50008517c688825bb1e27d56 (patch) | |
tree | b6b3daee681898e8d5610c3266a6ceaed944e099 | |
parent | cfd85329f41cfce2c3b9454b6d57ec0278dc97d0 (diff) | |
download | isort-63067802cedb570b50008517c688825bb1e27d56.tar.gz |
Fix issue 751
-rw-r--r-- | isort/api.py | 2 | ||||
-rw-r--r-- | tests/test_isort.py | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/isort/api.py b/isort/api.py index 1148035d..41a919b6 100644 --- a/isort/api.py +++ b/isort/api.py @@ -176,7 +176,7 @@ def sort_imports( stripped_line = line.strip() if ( - (index == 0 or (index == 1 and not contains_imports)) + (index == 0 or (index in (1, 2) and not contains_imports)) and stripped_line.startswith("#") and stripped_line not in section_comments ): diff --git a/tests/test_isort.py b/tests/test_isort.py index 2580fae7..66398eca 100644 --- a/tests/test_isort.py +++ b/tests/test_isort.py @@ -4783,3 +4783,26 @@ def test_comments_top_of_file(): from foo import * """ assert SortImports(file_contents=test_input).output == test_input + + test_input = """# -*- coding: utf-8 -*- + +# Define your item pipelines here +# +# Don't forget to add your pipeline to the ITEM_PIPELINES setting +# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html +from datetime import datetime + +from .items import WeiboMblogItem + + +class WeiboMblogPipeline(object): + def process_item(self, item, spider): + if isinstance(item, WeiboMblogItem): + item = self._process_item(item, spider) + return item + + def _process_item(self, item, spider): + item['inserted_at'] = datetime.now() + return item +""" + assert SortImports(file_contents=test_input).output == test_input |