diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-22 13:37:56 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-05-22 13:37:56 (GMT) |
commit | 7df55dad3bd130992f5d978e8baf1119a7f2090b (patch) | |
tree | 977dc8c6e618ffdc1fb9a3ba67409b644217297b /Lib/test/test_codecs.py | |
parent | 54d2898ef85271f8fba369826469c16d59267a1a (diff) | |
download | cpython-7df55dad3bd130992f5d978e8baf1119a7f2090b.zip cpython-7df55dad3bd130992f5d978e8baf1119a7f2090b.tar.gz cpython-7df55dad3bd130992f5d978e8baf1119a7f2090b.tar.bz2 |
Issue #6268: More bugfixes about BOM, UTF-16 and UTF-32
* Fix seek() method of codecs.open(), don't write the BOM twice after seek(0)
* Fix reset() method of codecs, UTF-16, UTF-32 and StreamWriter classes
* test_codecs: use "w+" mode instead of "wt+". "t" mode is not supported by
Solaris or Windows, but does it really exist? I found it the in the issue.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 306a3b2..ff91ce4 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1498,7 +1498,7 @@ class WithStmtTest(unittest.TestCase): class BomTest(unittest.TestCase): def test_seek0(self): - data = "1234567890" + data = u"1234567890" tests = ("utf-16", "utf-16-le", "utf-16-be", @@ -1506,8 +1506,8 @@ class BomTest(unittest.TestCase): "utf-32-le", "utf-32-be") for encoding in tests: - with codecs.open('foo', 'wt+', encoding=encoding) as f: - # Check if the BOM is written only once + # Check if the BOM is written only once + with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: f.write(data) f.write(data) f.seek(0) @@ -1515,6 +1515,42 @@ class BomTest(unittest.TestCase): f.seek(0) self.assertEquals(f.read(), data * 2) + # Check that the BOM is written after a seek(0) + with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: + f.write(data[0]) + self.assertNotEquals(f.tell(), 0) + f.seek(0) + f.write(data) + f.seek(0) + self.assertEquals(f.read(), data) + + # (StreamWriter) Check that the BOM is written after a seek(0) + with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: + f.writer.write(data[0]) + self.assertNotEquals(f.writer.tell(), 0) + f.writer.seek(0) + f.writer.write(data) + f.seek(0) + self.assertEquals(f.read(), data) + + # Check that the BOM is not written after a seek() at a position + # different than the start + with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: + f.write(data) + f.seek(f.tell()) + f.write(data) + f.seek(0) + self.assertEquals(f.read(), data * 2) + + # (StreamWriter) Check that the BOM is not written after a seek() + # at a position different than the start + with codecs.open(test_support.TESTFN, 'w+', encoding=encoding) as f: + f.writer.write(data) + f.writer.seek(f.writer.tell()) + f.writer.write(data) + f.seek(0) + self.assertEquals(f.read(), data * 2) + def test_main(): test_support.run_unittest( |