bpo-34108: Fix double carriage return in 2to3 on Windows (GH-8271) (#8275)

* Add test capturing failure.
* Honor newlines as present in the original file.
(cherry picked from commit cafaf0447b)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
Miss Islington (bot) 2018-07-13 12:24:19 -07:00 committed by Jason R. Coombs
parent 08c1da7103
commit cf21d0031d
3 changed files with 3 additions and 1 deletions

View File

@ -514,7 +514,7 @@ class RefactoringTool(object):
set.
"""
try:
fp = io.open(filename, "w", encoding=encoding)
fp = io.open(filename, "w", encoding=encoding, newline='')
except OSError as err:
self.log_error("Can't create %s: %s", filename, err)
return

View File

@ -300,6 +300,7 @@ from __future__ import print_function"""
old, new = self.refactor_file(fn)
self.assertIn(b"\r\n", old)
self.assertIn(b"\r\n", new)
self.assertNotIn(b"\r\r\n", new)
def test_refactor_docstring(self):
rt = self.rt()

View File

@ -0,0 +1 @@
Remove extraneous CR in 2to3 refactor.