Skip to content

Commit 00033db

Browse files
committed
Fix an unfinished though in my own test code.
(testNewlinesInput and testNewlinesOutput are mine, not Tony's.)
1 parent 1759666 commit 00033db

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

Lib/test/test_io.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -571,29 +571,31 @@ def testNewlinesInput(self):
571571
self.assertEquals(txt.read(), "".join(expected))
572572

573573
def testNewlinesOutput(self):
574-
import os
575-
orig_linesep = os.linesep
576574
data = "AAA\nBBB\rCCC\n"
577575
data_lf = b"AAA\nBBB\rCCC\n"
578576
data_cr = b"AAA\rBBB\rCCC\r"
579577
data_crlf = b"AAA\r\nBBB\rCCC\r\n"
580-
for os.linesep, newline, expected in [
581-
("\n", None, data_lf),
582-
("\r\n", None, data_crlf),
583-
("\n", "", data_lf),
584-
("\r\n", "", data_lf),
585-
("\n", "\n", data_lf),
586-
("\r\n", "\n", data_lf),
587-
("\n", "\r", data_cr),
588-
("\r\n", "\r", data_cr),
589-
("\n", "\r\n", data_crlf),
590-
("\r\n", "\r\n", data_crlf),
591-
]:
592-
buf = io.BytesIO()
593-
txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
594-
txt.write(data)
595-
txt.close()
596-
self.assertEquals(buf.getvalue(), expected)
578+
save_linesep = os.linesep
579+
try:
580+
for os.linesep, newline, expected in [
581+
("\n", None, data_lf),
582+
("\r\n", None, data_crlf),
583+
("\n", "", data_lf),
584+
("\r\n", "", data_lf),
585+
("\n", "\n", data_lf),
586+
("\r\n", "\n", data_lf),
587+
("\n", "\r", data_cr),
588+
("\r\n", "\r", data_cr),
589+
("\n", "\r\n", data_crlf),
590+
("\r\n", "\r\n", data_crlf),
591+
]:
592+
buf = io.BytesIO()
593+
txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
594+
txt.write(data)
595+
txt.close()
596+
self.assertEquals(buf.getvalue(), expected)
597+
finally:
598+
os.linesep = save_linesep
597599

598600
# Systematic tests of the text I/O API
599601

0 commit comments

Comments
 (0)