mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
(Merge 3.1) 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.
This commit is contained in:
commit
d48ba0bde5
3 changed files with 38 additions and 4 deletions
|
@ -256,6 +256,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 = '\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 = '\u804a\u804a'
|
||||
encoding = 'hz'
|
||||
expected = b'~{ADAD'
|
||||
expected_reset = b'~{ADAD~}'
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(__name__)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue