summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-22 16:59:09 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-22 16:59:09 (GMT)
commita92ad7ee2cfd4e81c22a7715aa0278196d9da664 (patch)
treeb56c15ee389d4409a703614122260378cc07468a /Lib/test/test_codecs.py
parentfff532bef328f78ac149123845b1962d9ca5ba59 (diff)
downloadcpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.zip
cpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.tar.gz
cpython-a92ad7ee2cfd4e81c22a7715aa0278196d9da664.tar.bz2
Merged revisions 81471-81472 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81471 | victor.stinner | 2010-05-22 15:37:56 +0200 (sam., 22 mai 2010) | 7 lines 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. ........ r81472 | victor.stinner | 2010-05-22 15:44:25 +0200 (sam., 22 mai 2010) | 4 lines Fix my last commit (r81471) about codecs Rememder: don't touch the code just before a commit ........
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 6e7afc4..598aaa2 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1604,8 +1604,8 @@ class BomTest(unittest.TestCase):
"utf-32-le",
"utf-32-be")
for encoding in tests:
- with codecs.open('foo', 'w+', encoding=encoding) as f:
- # Check if the BOM is written only once
+ # Check if the BOM is written only once
+ with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.write(data)
f.write(data)
f.seek(0)
@@ -1613,6 +1613,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(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(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(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(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():
support.run_unittest(