|
32 | 32 | import unittest |
33 | 33 | import warnings |
34 | 34 | import weakref |
35 | | -from collections import deque |
| 35 | +from collections import deque, UserList |
36 | 36 | from itertools import cycle, count |
37 | 37 | from test import support |
38 | 38 |
|
@@ -1201,6 +1201,29 @@ def test_flush(self): |
1201 | 1201 | bufio.flush() |
1202 | 1202 | self.assertEqual(b"abc", writer._write_stack[0]) |
1203 | 1203 |
|
| 1204 | + def test_writelines(self): |
| 1205 | + l = [b'ab', b'cd', b'ef'] |
| 1206 | + writer = self.MockRawIO() |
| 1207 | + bufio = self.tp(writer, 8) |
| 1208 | + bufio.writelines(l) |
| 1209 | + bufio.flush() |
| 1210 | + self.assertEqual(b''.join(writer._write_stack), b'abcdef') |
| 1211 | + |
| 1212 | + def test_writelines_userlist(self): |
| 1213 | + l = UserList([b'ab', b'cd', b'ef']) |
| 1214 | + writer = self.MockRawIO() |
| 1215 | + bufio = self.tp(writer, 8) |
| 1216 | + bufio.writelines(l) |
| 1217 | + bufio.flush() |
| 1218 | + self.assertEqual(b''.join(writer._write_stack), b'abcdef') |
| 1219 | + |
| 1220 | + def test_writelines_error(self): |
| 1221 | + writer = self.MockRawIO() |
| 1222 | + bufio = self.tp(writer, 8) |
| 1223 | + self.assertRaises(TypeError, bufio.writelines, [1, 2, 3]) |
| 1224 | + self.assertRaises(TypeError, bufio.writelines, None) |
| 1225 | + self.assertRaises(TypeError, bufio.writelines, 'abc') |
| 1226 | + |
1204 | 1227 | def test_destructor(self): |
1205 | 1228 | writer = self.MockRawIO() |
1206 | 1229 | bufio = self.tp(writer, 8) |
@@ -2304,6 +2327,28 @@ def test_read_by_chunk(self): |
2304 | 2327 | reads += c |
2305 | 2328 | self.assertEqual(reads, "A"*127+"\nB") |
2306 | 2329 |
|
| 2330 | + def test_writelines(self): |
| 2331 | + l = ['ab', 'cd', 'ef'] |
| 2332 | + buf = self.BytesIO() |
| 2333 | + txt = self.TextIOWrapper(buf) |
| 2334 | + txt.writelines(l) |
| 2335 | + txt.flush() |
| 2336 | + self.assertEqual(buf.getvalue(), b'abcdef') |
| 2337 | + |
| 2338 | + def test_writelines_userlist(self): |
| 2339 | + l = UserList(['ab', 'cd', 'ef']) |
| 2340 | + buf = self.BytesIO() |
| 2341 | + txt = self.TextIOWrapper(buf) |
| 2342 | + txt.writelines(l) |
| 2343 | + txt.flush() |
| 2344 | + self.assertEqual(buf.getvalue(), b'abcdef') |
| 2345 | + |
| 2346 | + def test_writelines_error(self): |
| 2347 | + txt = self.TextIOWrapper(self.BytesIO()) |
| 2348 | + self.assertRaises(TypeError, txt.writelines, [1, 2, 3]) |
| 2349 | + self.assertRaises(TypeError, txt.writelines, None) |
| 2350 | + self.assertRaises(TypeError, txt.writelines, b'abc') |
| 2351 | + |
2307 | 2352 | def test_issue1395_1(self): |
2308 | 2353 | txt = self.TextIOWrapper(self.BytesIO(self.testdata), encoding="ascii") |
2309 | 2354 |
|
|
0 commit comments