summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-10-16 21:02:27 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-10-16 21:02:27 (GMT)
commit3ed2cb5520fe1ad05664db41f7bac96438efc7d2 (patch)
tree2e0a3f2c384c8783699f3b72059c6693d32432d3
parent131a489903cd03706c3cc571b94ea702e0f29c2e (diff)
downloadcpython-3ed2cb5520fe1ad05664db41f7bac96438efc7d2.zip
cpython-3ed2cb5520fe1ad05664db41f7bac96438efc7d2.tar.gz
cpython-3ed2cb5520fe1ad05664db41f7bac96438efc7d2.tar.bz2
Also add tests for TextIOWrapper.writelines() (issue #15744).
-rw-r--r--Lib/test/test_io.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 6fc3c73..56ac2c8 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2287,6 +2287,28 @@ class TextIOWrapperTest(unittest.TestCase):
reads += c
self.assertEqual(reads, "A"*127+"\nB")
+ def test_writelines(self):
+ l = ['ab', 'cd', 'ef']
+ buf = self.BytesIO()
+ txt = self.TextIOWrapper(buf)
+ txt.writelines(l)
+ txt.flush()
+ self.assertEqual(buf.getvalue(), b'abcdef')
+
+ def test_writelines_userlist(self):
+ l = UserList(['ab', 'cd', 'ef'])
+ buf = self.BytesIO()
+ txt = self.TextIOWrapper(buf)
+ txt.writelines(l)
+ txt.flush()
+ self.assertEqual(buf.getvalue(), b'abcdef')
+
+ def test_writelines_error(self):
+ txt = self.TextIOWrapper(self.BytesIO())
+ self.assertRaises(TypeError, txt.writelines, [1, 2, 3])
+ self.assertRaises(TypeError, txt.writelines, None)
+ self.assertRaises(TypeError, txt.writelines, b'abc')
+
def test_issue1395_1(self):
txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii")