mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merge for issue #15744: add tests for the writelines() method of file objects.
This commit is contained in:
commit
0c7081aff4
2 changed files with 68 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue