[Python-checkins] r72493 - in sandbox/trunk/2to3/lib2to3: refactor.py tests/data/crlf.py tests/test_refactor.py
benjamin.peterson
python-checkins at python.org
Sat May 9 02:54:16 CEST 2009
Author: benjamin.peterson
Date: Sat May 9 02:54:15 2009
New Revision: 72493
Log:
add a test for \r\n newlines
Added:
sandbox/trunk/2to3/lib2to3/tests/data/crlf.py (contents, props changed)
Modified:
sandbox/trunk/2to3/lib2to3/refactor.py
sandbox/trunk/2to3/lib2to3/tests/test_refactor.py
Modified: sandbox/trunk/2to3/lib2to3/refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/refactor.py (original)
+++ sandbox/trunk/2to3/lib2to3/refactor.py Sat May 9 02:54:15 2009
@@ -95,11 +95,11 @@
# codecs.open doesn't translate newlines sadly.
def _from_system_newlines(input):
return input.replace(u"\r\n", u"\n")
- if os.linesep != "\n":
- def _to_system_newlines(input):
+ def _to_system_newlines(input):
+ if os.linesep != "\n":
return input.replace(u"\n", os.linesep)
- else:
- _to_system_newlines = _identity
+ else:
+ return input
else:
_open_with_encoding = open
_from_system_newlines = _identity
Added: sandbox/trunk/2to3/lib2to3/tests/data/crlf.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/lib2to3/tests/data/crlf.py Sat May 9 02:54:15 2009
@@ -0,0 +1,3 @@
+print "hi"
+
+print "Like bad Windows newlines?"
Modified: sandbox/trunk/2to3/lib2to3/tests/test_refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_refactor.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_refactor.py Sat May 9 02:54:15 2009
@@ -14,7 +14,8 @@
from . import support
-FIXER_DIR = os.path.join(os.path.dirname(__file__), "data/fixers")
+TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
+FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")
sys.path.append(FIXER_DIR)
try:
@@ -22,6 +23,8 @@
finally:
sys.path.pop()
+_2TO3_FIXERS = refactor.get_fixers_from_package("lib2to3.fixes")
+
class TestRefactoringTool(unittest.TestCase):
def setUp(self):
@@ -121,7 +124,7 @@
+def cheese(): pass""".splitlines()
self.assertEqual(diff_lines[:-1], expected)
- def check_file_refactoring(self, test_file, fixers=_DEFAULT_FIXERS):
+ def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS):
def read_file():
with open(test_file, "rb") as fp:
return fp.read()
@@ -140,12 +143,21 @@
def test_refactor_file(self):
test_file = os.path.join(FIXER_DIR, "parrot_example.py")
- self.check_file_refactoring(test_file)
+ self.check_file_refactoring(test_file, _DEFAULT_FIXERS)
def test_file_encoding(self):
- fn = os.path.join(FIXER_DIR, "..", "different_encoding.py")
- fixes = refactor.get_fixers_from_package("lib2to3.fixes")
- self.check_file_refactoring(fn, fixes)
+ fn = os.path.join(TEST_DATA_DIR, "different_encoding.py")
+ self.check_file_refactoring(fn)
+
+ def test_crlf_newlines(self):
+ old_sep = os.linesep
+ os.linesep = "\r\n"
+ try:
+ fn = os.path.join(TEST_DATA_DIR, "crlf.py")
+ fixes = refactor.get_fixers_from_package("lib2to3.fixes")
+ self.check_file_refactoring(fn, fixes)
+ finally:
+ os.linesep = old_sep
def test_refactor_docstring(self):
rt = self.rt()
More information about the Python-checkins
mailing list