Skip to content

Commit 91b800d

Browse files
committed
Add a(nother) test for issue #121
Also fix up the import-order checking code in future.tests.base
1 parent 0270a4b commit 91b800d

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/future/tests/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def order_future_lines(code):
4444
if line.startswith('from __future__ import ')]
4545

4646
future_line_numbers = [i for i, line in enumerate(lines)
47-
if line.startswith('from future')]
47+
if line.startswith('from future')
48+
or line.startswith('from past')]
4849

4950
builtins_line_numbers = [i for i, line in enumerate(lines)
5051
if line.startswith('from builtins')]
@@ -56,7 +57,7 @@ def mymax(numbers):
5657
return max(numbers) if len(numbers) > 0 else 0
5758

5859
def mymin(numbers):
59-
return min(numbers) if len(numbers) > 0 else 0
60+
return min(numbers) if len(numbers) > 0 else float('inf')
6061

6162
assert mymax(uufuture_line_numbers) <= mymin(future_line_numbers), \
6263
'the __future__ and future imports are out of order'

tests/test_future/test_futurize.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,22 @@ def test_encoding_comments_kept_at_top(self):
104104
from __future__ import print_function
105105
print('Hello')
106106
"""
107-
self.convert_check(before, after)
107+
self.convert_check(before, after, ignore_imports=False)
108+
109+
# Issue #121. This fails as of v0.14.1:
110+
before = u"""
111+
# -*- coding: utf-8 -*-
112+
# Author: etc. with some unicode ¿.
113+
1 / 2
114+
"""
115+
after = u"""
116+
# -*- coding: utf-8 -*-
117+
# Author: etc. with some unicode ¿.
118+
from __future__ import division
119+
from past.utils import old_div
120+
old_div(1, 2)
121+
"""
122+
self.convert_check(before, after, ignore_imports=False)
108123

109124
def test_shebang_blank_with_future_division_import(self):
110125
"""
@@ -435,7 +450,7 @@ def test_source_coding_utf8(self):
435450
"""
436451
code = """
437452
# -*- coding: utf-8 -*-
438-
icons = [u"", u"", u"", u""]
453+
icons = [u"◐", u"◓", u"◑", u"◒"]
439454
"""
440455
self.unchanged(code)
441456

0 commit comments

Comments
 (0)