Skip to content

Commit ea484c1

Browse files
committed
Add (failing) test for whether futurize displaces PEP 263 source encoding comments (issues #97 and #10)
1 parent 4f41948 commit ea484c1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_future/test_futurize.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,39 @@ def setUp(self):
3636
self.tempdir = tempfile.mkdtemp() + os.path.sep
3737
super(TestFuturizeSimple, self).setUp()
3838

39+
def test_encoding_comments_kept_at_top(self):
40+
"""
41+
Issues #10 and #97: If there is a source encoding comment line
42+
(PEP 263), is it kept at the top of a module by ``futurize``?
43+
"""
44+
before = """
45+
# coding=utf-8
46+
47+
print 'Hello'
48+
"""
49+
after = """
50+
# coding=utf-8
51+
52+
from __future__ import print_function
53+
print('Hello')
54+
"""
55+
self.convert_check(before, after)
56+
57+
before = """
58+
#!/usr/bin/env python
59+
# -*- coding: latin-1 -*-"
60+
61+
print 'Hello'
62+
"""
63+
after = """
64+
#!/usr/bin/env python
65+
# -*- coding: latin-1 -*-"
66+
67+
from __future__ import print_function
68+
print('Hello')
69+
"""
70+
self.convert_check(before, after)
71+
3972
def test_shebang_blank_with_future_division_import(self):
4073
"""
4174
Issue #43: Is shebang line preserved as the first

0 commit comments

Comments
 (0)