summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r--Lib/lib2to3/tests/data/bom.py3
-rwxr-xr-xLib/lib2to3/tests/test_fixers.py15
-rw-r--r--Lib/lib2to3/tests/test_refactor.py20
3 files changed, 28 insertions, 10 deletions
diff --git a/Lib/lib2to3/tests/data/bom.py b/Lib/lib2to3/tests/data/bom.py
new file mode 100644
index 0000000..ecb782a
--- /dev/null
+++ b/Lib/lib2to3/tests/data/bom.py
@@ -0,0 +1,3 @@
+# coding: utf-8
+print "BOM BOOM!"
+
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index cad2a7d..eb0b4b4 100755
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -1753,6 +1753,8 @@ class Test_urllib(FixerTestCase):
for old, changes in self.modules.items():
for new, members in changes:
for member in members:
+ new_import = ", ".join([n for (n, mems)
+ in self.modules[old]])
b = """
import %s
foo(%s.%s)
@@ -1760,9 +1762,16 @@ class Test_urllib(FixerTestCase):
a = """
import %s
foo(%s.%s)
- """ % (", ".join([n for (n, mems)
- in self.modules[old]]),
- new, member)
+ """ % (new_import, new, member)
+ self.check(b, a)
+ b = """
+ import %s
+ %s.%s(%s.%s)
+ """ % (old, old, member, old, member)
+ a = """
+ import %s
+ %s.%s(%s.%s)
+ """ % (new_import, new, member, new, member)
self.check(b, a)
diff --git a/Lib/lib2to3/tests/test_refactor.py b/Lib/lib2to3/tests/test_refactor.py
index cc47b9d..1729027 100644
--- a/Lib/lib2to3/tests/test_refactor.py
+++ b/Lib/lib2to3/tests/test_refactor.py
@@ -4,6 +4,7 @@ Unit tests for refactor.py.
import sys
import os
+import codecs
import operator
import StringIO
import tempfile
@@ -45,12 +46,10 @@ class TestRefactoringTool(unittest.TestCase):
return refactor.RefactoringTool(fixers, options, explicit)
def test_print_function_option(self):
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always", DeprecationWarning)
- refactor.RefactoringTool(_DEFAULT_FIXERS, {"print_function" : True})
- self.assertEqual(len(w), 1)
- msg, = w
- self.assertTrue(msg.category is DeprecationWarning)
+ rt = self.rt({"print_function" : True})
+ self.assertTrue(rt.grammar is pygram.python_grammar_no_print_statement)
+ self.assertTrue(rt.driver.grammar is
+ pygram.python_grammar_no_print_statement)
def test_fixer_loading_helpers(self):
contents = ["explicit", "first", "last", "parrot", "preorder"]
@@ -179,10 +178,12 @@ from __future__ import print_function"""
try:
rt.refactor_file(test_file, True)
- self.assertNotEqual(old_contents, read_file())
+ new_contents = read_file()
+ self.assertNotEqual(old_contents, new_contents)
finally:
with open(test_file, "wb") as fp:
fp.write(old_contents)
+ return new_contents
def test_refactor_file(self):
test_file = os.path.join(FIXER_DIR, "parrot_example.py")
@@ -223,6 +224,11 @@ from __future__ import print_function"""
fn = os.path.join(TEST_DATA_DIR, "different_encoding.py")
self.check_file_refactoring(fn)
+ def test_bom(self):
+ fn = os.path.join(TEST_DATA_DIR, "bom.py")
+ data = self.check_file_refactoring(fn)
+ self.assertTrue(data.startswith(codecs.BOM_UTF8))
+
def test_crlf_newlines(self):
old_sep = os.linesep
os.linesep = "\r\n"