summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fileio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-10-16 21:05:01 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-10-16 21:05:01 (GMT)
commit0c7081aff471cca50fb068094d8cae11bf705cc6 (patch)
tree993910ef6fc56992ca832d7e95e25029880cc7eb /Lib/test/test_fileio.py
parentad626807a6e2f22dbf7855d53cd93f3f8f7e6ac3 (diff)
parent3ed2cb5520fe1ad05664db41f7bac96438efc7d2 (diff)
downloadcpython-0c7081aff471cca50fb068094d8cae11bf705cc6.zip
cpython-0c7081aff471cca50fb068094d8cae11bf705cc6.tar.gz
cpython-0c7081aff471cca50fb068094d8cae11bf705cc6.tar.bz2
Merge for issue #15744: add tests for the writelines() method of file objects.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r--Lib/test/test_fileio.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 906952c..0847961 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -10,6 +10,7 @@ from weakref import proxy
from functools import wraps
from test.support import TESTFN, check_warnings, run_unittest, make_bad_fd
+from collections import UserList
from _io import FileIO as _FileIO
@@ -68,6 +69,27 @@ class AutoFileTests(unittest.TestCase):
n = self.f.readinto(a)
self.assertEqual(array('b', [1, 2]), a[:n])
+ def testWritelinesList(self):
+ l = [b'123', b'456']
+ self.f.writelines(l)
+ self.f.close()
+ self.f = _FileIO(TESTFN, 'rb')
+ buf = self.f.read()
+ self.assertEqual(buf, b'123456')
+
+ def testWritelinesUserList(self):
+ l = UserList([b'123', b'456'])
+ self.f.writelines(l)
+ self.f.close()
+ self.f = _FileIO(TESTFN, 'rb')
+ buf = self.f.read()
+ self.assertEqual(buf, b'123456')
+
+ def testWritelinesError(self):
+ self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])
+ self.assertRaises(TypeError, self.f.writelines, None)
+ self.assertRaises(TypeError, self.f.writelines, "abc")
+
def test_none_args(self):
self.f.write(b"hi\nbye\nabc")
self.f.close()