summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-18 22:05:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-18 22:05:58 (GMT)
commit1836358c016cd7f5117f4f34fa3a27c5701e8265 (patch)
treefd7f75e65d85dc3566c9b9a82034b1a77313d610
parent8358db22faa3d8fa9ac0ef2f2c1ff1770a843996 (diff)
downloadcpython-1836358c016cd7f5117f4f34fa3a27c5701e8265.zip
cpython-1836358c016cd7f5117f4f34fa3a27c5701e8265.tar.gz
cpython-1836358c016cd7f5117f4f34fa3a27c5701e8265.tar.bz2
Fix an unfinished though in my own test code.
(testNewlinesInput and testNewlinesOutput are mine, not Tony's.)
-rw-r--r--Lib/test/test_io.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 92e1567..f8a4938 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -571,29 +571,31 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertEquals(txt.read(), "".join(expected))
def testNewlinesOutput(self):
- import os
- orig_linesep = os.linesep
data = "AAA\nBBB\rCCC\n"
data_lf = b"AAA\nBBB\rCCC\n"
data_cr = b"AAA\rBBB\rCCC\r"
data_crlf = b"AAA\r\nBBB\rCCC\r\n"
- for os.linesep, newline, expected in [
- ("\n", None, data_lf),
- ("\r\n", None, data_crlf),
- ("\n", "", data_lf),
- ("\r\n", "", data_lf),
- ("\n", "\n", data_lf),
- ("\r\n", "\n", data_lf),
- ("\n", "\r", data_cr),
- ("\r\n", "\r", data_cr),
- ("\n", "\r\n", data_crlf),
- ("\r\n", "\r\n", data_crlf),
- ]:
- buf = io.BytesIO()
- txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
- txt.write(data)
- txt.close()
- self.assertEquals(buf.getvalue(), expected)
+ save_linesep = os.linesep
+ try:
+ for os.linesep, newline, expected in [
+ ("\n", None, data_lf),
+ ("\r\n", None, data_crlf),
+ ("\n", "", data_lf),
+ ("\r\n", "", data_lf),
+ ("\n", "\n", data_lf),
+ ("\r\n", "\n", data_lf),
+ ("\n", "\r", data_cr),
+ ("\r\n", "\r", data_cr),
+ ("\n", "\r\n", data_crlf),
+ ("\r\n", "\r\n", data_crlf),
+ ]:
+ buf = io.BytesIO()
+ txt = io.TextIOWrapper(buf, encoding="ASCII", newline=newline)
+ txt.write(data)
+ txt.close()
+ self.assertEquals(buf.getvalue(), expected)
+ finally:
+ os.linesep = save_linesep
# Systematic tests of the text I/O API