diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-09 10:20:18 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-09 10:20:18 (GMT) |
commit | beaa3adae954a4a85c7dd8e02340d92fd04a7855 (patch) | |
tree | 84a56549222a3424a824583d2a94c8a95de76811 /Lib/test/test_tempfile.py | |
parent | 62e709c52b0bd8ceba5fbcf2316665e20b8eb70e (diff) | |
download | cpython-beaa3adae954a4a85c7dd8e02340d92fd04a7855.zip cpython-beaa3adae954a4a85c7dd8e02340d92fd04a7855.tar.gz cpython-beaa3adae954a4a85c7dd8e02340d92fd04a7855.tar.bz2 |
Issue #10355: SpooledTemporaryFile properties and xreadline method now work for unrolled files.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r-- | Lib/test/test_tempfile.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 2ddc04c..1b219c8 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -738,6 +738,17 @@ class test_SpooledTemporaryFile(TC): f.write(b'x') self.assertTrue(f._rolled) + def test_xreadlines(self): + f = self.do_create(max_size=20) + f.write(b'abc\n' * 5) + f.seek(0) + self.assertFalse(f._rolled) + self.assertEqual(list(f.xreadlines()), [b'abc\n'] * 5) + f.write(b'x\ny') + self.assertTrue(f._rolled) + f.seek(0) + self.assertEqual(list(f.xreadlines()), [b'abc\n'] * 5 + [b'x\n', b'y']) + def test_sparse(self): # A SpooledTemporaryFile that is written late in the file will extend # when that occurs @@ -793,6 +804,26 @@ class test_SpooledTemporaryFile(TC): seek(0, 0) self.assertTrue(read(70) == 'a'*35 + 'b'*35) + def test_properties(self): + f = tempfile.SpooledTemporaryFile(max_size=10) + f.write(b'x' * 10) + self.assertFalse(f._rolled) + self.assertEqual(f.mode, 'w+b') + self.assertIsNone(f.name) + with self.assertRaises(AttributeError): + f.newlines + with self.assertRaises(AttributeError): + f.encoding + + f.write(b'x') + self.assertTrue(f._rolled) + self.assertEqual(f.mode, 'w+b') + self.assertIsNotNone(f.name) + with self.assertRaises(AttributeError): + f.newlines + with self.assertRaises(AttributeError): + f.encoding + def test_context_manager_before_rollover(self): # A SpooledTemporaryFile can be used as a context manager with tempfile.SpooledTemporaryFile(max_size=1) as f: |