mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Fix an unfinished though in my own test code.
(testNewlinesInput and testNewlinesOutput are mine, not Tony's.)
This commit is contained in:
parent
8358db22fa
commit
1836358c01
1 changed files with 21 additions and 19 deletions
|
|
@ -571,29 +571,31 @@ class TextIOWrapperTest(unittest.TestCase):
|
||||||
self.assertEquals(txt.read(), "".join(expected))
|
self.assertEquals(txt.read(), "".join(expected))
|
||||||
|
|
||||||
def testNewlinesOutput(self):
|
def testNewlinesOutput(self):
|
||||||
import os
|
|
||||||
orig_linesep = os.linesep
|
|
||||||
data = "AAA\nBBB\rCCC\n"
|
data = "AAA\nBBB\rCCC\n"
|
||||||
data_lf = b"AAA\nBBB\rCCC\n"
|
data_lf = b"AAA\nBBB\rCCC\n"
|
||||||
data_cr = b"AAA\rBBB\rCCC\r"
|
data_cr = b"AAA\rBBB\rCCC\r"
|
||||||
data_crlf = b"AAA\r\nBBB\rCCC\r\n"
|
data_crlf = b"AAA\r\nBBB\rCCC\r\n"
|
||||||
for os.linesep, newline, expected in [
|
save_linesep = os.linesep
|
||||||
("\n", None, data_lf),
|
try:
|
||||||
("\r\n", None, data_crlf),
|
for os.linesep, newline, expected in [
|
||||||
("\n", "", data_lf),
|
("\n", None, data_lf),
|
||||||
("\r\n", "", data_lf),
|
("\r\n", None, data_crlf),
|
||||||
("\n", "\n", data_lf),
|
("\n", "", data_lf),
|
||||||
("\r\n", "\n", data_lf),
|
("\r\n", "", data_lf),
|
||||||
("\n", "\r", data_cr),
|
("\n", "\n", data_lf),
|
||||||
("\r\n", "\r", data_cr),
|
("\r\n", "\n", data_lf),
|
||||||
("\n", "\r\n", data_crlf),
|
("\n", "\r", data_cr),
|
||||||
("\r\n", "\r\n", data_crlf),
|
("\r\n", "\r", data_cr),
|
||||||
]:
|
("\n", "\r\n", data_crlf),
|
||||||
buf = io.BytesIO()
|
("\r\n", "\r\n", data_crlf),
|
||||||
txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
|
]:
|
||||||
txt.write(data)
|
buf = io.BytesIO()
|
||||||
txt.close()
|
txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
|
||||||
self.assertEquals(buf.getvalue(), expected)
|
txt.write(data)
|
||||||
|
txt.close()
|
||||||
|
self.assertEquals(buf.getvalue(), expected)
|
||||||
|
finally:
|
||||||
|
os.linesep = save_linesep
|
||||||
|
|
||||||
# Systematic tests of the text I/O API
|
# Systematic tests of the text I/O API
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue