diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-10-16 20:57:11 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-10-16 20:57:11 (GMT) |
commit | 131a489903cd03706c3cc571b94ea702e0f29c2e (patch) | |
tree | 03e13b87d930cf2498ab947d512e5813191af769 /Lib/test/test_fileio.py | |
parent | 6603118125164b927d79eab89263a07a12406481 (diff) | |
download | cpython-131a489903cd03706c3cc571b94ea702e0f29c2e.zip cpython-131a489903cd03706c3cc571b94ea702e0f29c2e.tar.gz cpython-131a489903cd03706c3cc571b94ea702e0f29c2e.tar.bz2 |
Add tests for the writelines() method of file objects.
Original patch by Felipe Cruz.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r-- | Lib/test/test_fileio.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 5504ea3..b5bd8d4 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -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() |