diff options
author | Guido van Rossum <guido@python.org> | 2007-07-09 10:24:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-09 10:24:45 (GMT) |
commit | 9a63470fd7f1d96eff03ffd33bf75371d5bb6fac (patch) | |
tree | d6ed7a64fc9f557d04bef5d9285c807b10a105b3 /Lib/test/test_tempfile.py | |
parent | b4e87e379219afd6ef1a0fba400275fa22180c63 (diff) | |
download | cpython-9a63470fd7f1d96eff03ffd33bf75371d5bb6fac.zip cpython-9a63470fd7f1d96eff03ffd33bf75371d5bb6fac.tar.gz cpython-9a63470fd7f1d96eff03ffd33bf75371d5bb6fac.tar.bz2 |
Make test_tempfile.py work. Make SpooledTempFile work in text and binary mode.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r-- | Lib/test/test_tempfile.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index caa8f4e..c925f68 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -664,7 +664,7 @@ class test_SpooledTemporaryFile(TC): self.failUnless(f._rolled) filename = f.name f.close() - self.failIf(os.path.exists(filename), + self.failIf(isinstance(filename, str) and os.path.exists(filename), "SpooledTemporaryFile %s exists after close" % filename) finally: os.rmdir(dir) @@ -730,7 +730,22 @@ class test_SpooledTemporaryFile(TC): write("a" * 35) write("b" * 35) seek(0, 0) - self.assertEqual(read(70), 'a'*35 + 'b'*35) + self.assertEqual(read(70), b'a'*35 + b'b'*35) + + def test_text_mode(self): + # Creating a SpooledTemporaryFile with a text mode should produce + # a file object reading and writing (Unicode) text strings. + f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10) + f.write("abc\n") + f.seek(0) + self.assertEqual(f.read(), "abc\n") + f.write("def\n") + f.seek(0) + self.assertEqual(f.read(), "abc\ndef\n") + f.write("xyzzy\n") + f.seek(0) + self.assertEqual(f.read(), "abc\ndef\nxyzzy\n") + test_classes.append(test_SpooledTemporaryFile) |