Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add 'absolute_import' futures indiscriminately #165

Merged
merged 1 commit into from Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion libmodernize/__init__.py
Expand Up @@ -77,7 +77,6 @@ def add_future(node, symbol):


def touch_import(package, name, node):
add_future(node, 'absolute_import')
fixer_util.touch_import(package, name, node)


Expand Down
1 change: 0 additions & 1 deletion tests/test_fix_open.py
Expand Up @@ -6,7 +6,6 @@
OPEN = ("""\
{0}('some/path')
""", """\
from __future__ import absolute_import
from io import open
open('some/path')
""")
Expand Down
22 changes: 16 additions & 6 deletions tests/utils.py
Expand Up @@ -10,12 +10,14 @@
def check_on_input(input_content, expected_content, extra_flags = [],
expected_return_code = None):
"""
Check that input_content is fixed to expected_content, idempotently.

Writes input_content to a temporary file, runs modernize on it with any
extra arguments as given in extra_flags, and asserts that the resulting file
matches expected_content. Then, runs modernize again with any extra arguments,
and asserts that the second run makes no changes.
Check that input_content is fixed to expected_content, idempotently:
Writes input_content to a temporary file
Runs modernize on it with any extra arguments as given in extra_flags
Runs modernize again with the same arguments, to flush out cumulative effects
(e.g., 'import' fixer isn't triggered until an import exists)
Asserts that the resulting file matches expected_content
Runs modernize again with any extra arguments
Asserts that the final run makes no changes
"""
tmpdirname = tempfile.mkdtemp()
try:
Expand All @@ -26,6 +28,14 @@ def check_on_input(input_content, expected_content, extra_flags = [],
def _check(this_input_content, which_check, check_return_code=True):
return_code = modernize_main(extra_flags + ["-w", test_input_name])

if check_return_code and expected_return_code is not None:
if expected_return_code != return_code:
raise AssertionError("Actual return code: %s\nExpected return code: %s" %
(return_code, expected_return_code))

# Second pass to deal with cumulative effects that affect 'import'
return_code = modernize_main(extra_flags + ["-w", test_input_name])

if check_return_code and expected_return_code is not None:
if expected_return_code != return_code:
raise AssertionError("Actual return code: %s\nExpected return code: %s" %
Expand Down