mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Add tests for the writelines() method of file objects.
Original patch by Felipe Cruz.
This commit is contained in:
parent
ce5a56e985
commit
78e761eafe
2 changed files with 44 additions and 0 deletions
|
@ -34,6 +34,7 @@ import signal
|
|||
import errno
|
||||
from itertools import cycle, count
|
||||
from collections import deque
|
||||
from UserList import UserList
|
||||
from test import test_support as support
|
||||
|
||||
import codecs
|
||||
|
@ -1126,6 +1127,28 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
|
|||
bufio.flush()
|
||||
self.assertEqual(b"abc", writer._write_stack[0])
|
||||
|
||||
def test_writelines(self):
|
||||
l = [b'ab', b'cd', b'ef']
|
||||
writer = self.MockRawIO()
|
||||
bufio = self.tp(writer, 8)
|
||||
bufio.writelines(l)
|
||||
bufio.flush()
|
||||
self.assertEqual(b''.join(writer._write_stack), b'abcdef')
|
||||
|
||||
def test_writelines_userlist(self):
|
||||
l = UserList([b'ab', b'cd', b'ef'])
|
||||
writer = self.MockRawIO()
|
||||
bufio = self.tp(writer, 8)
|
||||
bufio.writelines(l)
|
||||
bufio.flush()
|
||||
self.assertEqual(b''.join(writer._write_stack), b'abcdef')
|
||||
|
||||
def test_writelines_error(self):
|
||||
writer = self.MockRawIO()
|
||||
bufio = self.tp(writer, 8)
|
||||
self.assertRaises(TypeError, bufio.writelines, [1, 2, 3])
|
||||
self.assertRaises(TypeError, bufio.writelines, None)
|
||||
|
||||
def test_destructor(self):
|
||||
writer = self.MockRawIO()
|
||||
bufio = self.tp(writer, 8)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue