From: Antoine Pitrou Date: Tue, 16 Oct 2012 21:02:27 +0000 (+0200) Subject: Also add tests for TextIOWrapper.writelines() (issue #15744). X-Git-Tag: v2.7.4rc1~476 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eadca1defab2966714ece5b2218c98e9ee9e4394;p=thirdparty%2FPython%2Fcpython.git Also add tests for TextIOWrapper.writelines() (issue #15744). --- diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index a5d87b9d1c5e..d10f52a5528b 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -2233,6 +2233,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")