summaryrefslogtreecommitdiff
path: root/Lib/test/test_multibytecodec.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-24 22:29:13 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-24 22:29:13 +0200
commit40b41e1ffd4efc5718ed438a725765d6e4d1feae (patch)
tree9874cedb9f5d625f5bc05915f379ef41ced831a0 /Lib/test/test_multibytecodec.py
parent80a09c70bfa4592a8067274f49f24f9fffe8b795 (diff)
downloadcpython-git-40b41e1ffd4efc5718ed438a725765d6e4d1feae.tar.gz
Issue #12100: Don't reset incremental encoders of CJK codecs at each call to
their encode() method anymore, but continue to call the reset() method if the final argument is True.
Diffstat (limited to 'Lib/test/test_multibytecodec.py')
-rw-r--r--Lib/test/test_multibytecodec.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py
index 63c1e620b5..5e86ca2aae 100644
--- a/Lib/test/test_multibytecodec.py
+++ b/Lib/test/test_multibytecodec.py
@@ -237,6 +237,36 @@ class Test_ISO2022(unittest.TestCase):
# Any ISO 2022 codec will cause the segfault
myunichr(x).encode('iso_2022_jp', 'ignore')
+class TestStateful(unittest.TestCase):
+ text = u'\u4E16\u4E16'
+ encoding = 'iso-2022-jp'
+ expected = b'\x1b$B@$@$'
+ expected_reset = b'\x1b$B@$@$\x1b(B'
+
+ def test_encode(self):
+ self.assertEqual(self.text.encode(self.encoding), self.expected_reset)
+
+ def test_incrementalencoder(self):
+ encoder = codecs.getincrementalencoder(self.encoding)()
+ output = b''.join(
+ encoder.encode(char)
+ for char in self.text)
+ self.assertEqual(output, self.expected)
+
+ def test_incrementalencoder_final(self):
+ encoder = codecs.getincrementalencoder(self.encoding)()
+ last_index = len(self.text) - 1
+ output = b''.join(
+ encoder.encode(char, index == last_index)
+ for index, char in enumerate(self.text))
+ self.assertEqual(output, self.expected_reset)
+
+class TestHZStateful(TestStateful):
+ text = u'\u804a\u804a'
+ encoding = 'hz'
+ expected = b'~{ADAD'
+ expected_reset = b'~{ADAD~}'
+
def test_main():
test_support.run_unittest(__name__)