summaryrefslogtreecommitdiff
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-10-29 08:39:22 +0000
committerGeorg Brandl <georg@python.org>2006-10-29 08:39:22 +0000
commit8f99f81dfc5309205c2f93bd4dd205f97f586b0d (patch)
tree938fa01d5f2dc343366f439539805fd3bfd8f0d1 /Lib/test/test_codecs.py
parent4bb9b565011f2420649f851dc74e8fa3749046fa (diff)
downloadcpython-git-8f99f81dfc5309205c2f93bd4dd205f97f586b0d.tar.gz
Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and
fix all codecs file wrappers to work correctly with the "with" statement (bug #1586513).
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 8153979a85..39d4206cbd 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -910,6 +910,18 @@ class StreamReaderTest(unittest.TestCase):
f = self.reader(self.stream)
self.assertEquals(f.readlines(), [u'\ud55c\n', u'\uae00'])
+class EncodedFileTest(unittest.TestCase):
+
+ def test_basic(self):
+ f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80')
+ ef = codecs.EncodedFile(f, 'utf-16', 'utf-8')
+ self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae')
+
+ f = StringIO.StringIO()
+ ef = codecs.EncodedFile(f, 'utf-8', 'latin1')
+ ef.write('\xc3\xbc')
+ self.assertEquals(f.getvalue(), '\xfc')
+
class Str2StrTest(unittest.TestCase):
def test_read(self):
@@ -1214,6 +1226,19 @@ class CharmapTest(unittest.TestCase):
(u"", len(allbytes))
)
+class WithStmtTest(unittest.TestCase):
+ def test_encodedfile(self):
+ f = StringIO.StringIO("\xc3\xbc")
+ with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
+ self.assertEquals(ef.read(), "\xfc")
+
+ def test_streamreaderwriter(self):
+ f = StringIO.StringIO("\xc3\xbc")
+ info = codecs.lookup("utf-8")
+ with codecs.StreamReaderWriter(f, info.streamreader,
+ info.streamwriter, 'strict') as srw:
+ self.assertEquals(srw.read(), u"\xfc")
+
def test_main():
test_support.run_unittest(
@@ -1234,10 +1259,12 @@ def test_main():
IDNACodecTest,
CodecsModuleTest,
StreamReaderTest,
+ EncodedFileTest,
Str2StrTest,
BasicUnicodeTest,
BasicStrTest,
- CharmapTest
+ CharmapTest,
+ WithStmtTest,
)