FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix future import ordering by ascandella · Pull Request #446 · PythonCharmers/python-future · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion src/future/tests/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ def convert_check(self, before, expected, stages=(1, 2), all_imports=False,
else:
headers = ''

self.compare(output, headers + reformat_code(expected),
reformatted = reformat_code(expected)
if headers in reformatted:
headers = ''

self.compare(output, headers + reformatted,
ignore_imports=ignore_imports)

def unchanged(self, code, **kwargs):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class FixAddFutureImportsExceptUnicodeLiterals(fixer_base.BaseFix):

def transform(self, node, results):
# Reverse order:
future_import(u"print_function", node)
future_import(u"division", node)
future_import(u"absolute_import", node)
future_import(u"division", node)
future_import(u"print_function", node)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FixAddAllFutureImports(fixer_base.BaseFix):
run_order = 1

def transform(self, node, results):
future_import(u"unicode_literals", node)
future_import(u"print_function", node)
future_import(u"division", node)
future_import(u"absolute_import", node)
future_import(u"division", node)
future_import(u"print_function", node)
future_import(u"unicode_literals", node)
11 changes: 6 additions & 5 deletions tests/test_future/test_futurize.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ def test_open(self):
"""
self.convert_check(before, after, conservative=True)


class TestFuturizeAllImports(CodeHandler):
"""
Tests "futurize --all-imports".
Expand All @@ -1378,14 +1379,14 @@ def test_all_imports(self):
print('Hello')
"""
after = """
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from builtins import range
from builtins import *
from builtins import range
import math
import os
l = list(range(10))
Expand All @@ -1395,7 +1396,7 @@ def test_all_imports(self):
pass
print('Hello')
"""
self.convert_check(before, after, all_imports=True)
self.convert_check(before, after, all_imports=True, ignore_imports=False)


if __name__ == '__main__':
Expand Down

Back | FazBrowse Home | New Git URL