[Python-checkins] cpython (3.2): Also add tests for TextIOWrapper.writelines() (issue #15744).

antoine.pitrou python-checkins at python.org
Tue Oct 16 23:08:17 CEST 2012


http://hg.python.org/cpython/rev/4c204a61bd79
changeset:   79769:4c204a61bd79
branch:      3.2
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Tue Oct 16 23:02:27 2012 +0200
summary:
  Also add tests for TextIOWrapper.writelines() (issue #15744).

files:
  Lib/test/test_io.py |  22 ++++++++++++++++++++++
  1 files changed, 22 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2287,6 +2287,28 @@
             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")
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list