mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add tests for the writelines() method of file objects.
Original patch by Felipe Cruz.
This commit is contained in:
parent
6603118125
commit
131a489903
2 changed files with 46 additions and 1 deletions
|
@ -9,6 +9,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
|
||||
|
||||
|
@ -67,6 +68,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