diff options
author | Guido van Rossum <guido@python.org> | 2007-08-28 03:29:45 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-28 03:29:45 +0000 |
commit | 9ca36275a134fc79d9b198c1a9870170360497ac (patch) | |
tree | 85ebbad2e4f80ed56e43121cff93f06dea517f57 /Lib/test/test_tempfile.py | |
parent | 8c7542ad4aef74185696a276fc08d887a33abf7e (diff) | |
download | cpython-9ca36275a134fc79d9b198c1a9870170360497ac.tar.gz |
Patch # 1033 by Adam Hupp:
1) tempfile.TemporaryFile, NamedTemporaryFile, and SpooledTemporaryFile
now pass newline and encoding to the underlying io.open call.
2) test_tempfile is updated
3) test_csv is updated to use the new arguments.
Diffstat (limited to 'Lib/test/test_tempfile.py')
-rw-r--r-- | Lib/test/test_tempfile.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 07f32e8681..3e4f803d29 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -746,6 +746,18 @@ class test_SpooledTemporaryFile(TC): f.seek(0) self.assertEqual(f.read(), "abc\ndef\nxyzzy\n") + def test_text_newline_and_encoding(self): + f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10, + newline='', encoding='utf-8') + f.write("\u039B\r\n") + f.seek(0) + self.assertEqual(f.read(), "\u039B\r\n") + self.failIf(f._rolled) + + f.write("\u039B" * 20 + "\r\n") + f.seek(0) + self.assertEqual(f.read(), "\u039B\r\n" + ("\u039B" * 20) + "\r\n") + self.failUnless(f._rolled) test_classes.append(test_SpooledTemporaryFile) @@ -790,6 +802,18 @@ class test_TemporaryFile(TC): self.failOnException("close") # How to test the mode and bufsize parameters? + def test_mode_and_encoding(self): + + def roundtrip(input, *args, **kwargs): + with tempfile.TemporaryFile(*args, **kwargs) as fileobj: + fileobj.write(input) + fileobj.seek(0) + self.assertEquals(input, fileobj.read()) + + roundtrip(b"1234", "w+b") + roundtrip("abdc\n", "w+") + roundtrip("\u039B", "w+", encoding="utf-16") + roundtrip("foo\r\n", "w+", newline="") if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile: |