diff options
author | Victor Stinner <vstinner@python.org> | 2021-01-08 00:15:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-08 00:15:22 +0100 |
commit | 07f2cee93f1b619650403981c455f47bfed8d818 (patch) | |
tree | ded46be4aac83cba64d786c780101386ec2a6607 /Lib/test | |
parent | bpo-42860: Remove type error from grammar (GH-24156) (diff) | |
download | cpython-07f2cee93f1b619650403981c455f47bfed8d818.tar.gz cpython-07f2cee93f1b619650403981c455f47bfed8d818.tar.bz2 cpython-07f2cee93f1b619650403981c455f47bfed8d818.zip |
bpo-42846: Convert CJK codec extensions to multiphase init (GH-24157)
Convert the 6 CJK codec extension modules (_codecs_cn, _codecs_hk,
_codecs_iso2022, _codecs_jp, _codecs_kr and _codecs_tw) to the
multiphase initialization API (PEP 489).
Remove getmultibytecodec() local cache: always import
_multibytecodec. It should be uncommon to get a codec. For example,
this function is only called once per CJK codec module.
Fix a reference leak in register_maps() error path.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_multibytecodec.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index 7c3b67f3cbf..3efa1505e5c 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -3,11 +3,15 @@ # Unit test for multibytecodec itself # +import _multibytecodec +import codecs +import io +import sys +import textwrap +import unittest from test import support from test.support import os_helper from test.support.os_helper import TESTFN -import unittest, io, codecs, sys -import _multibytecodec ALL_CJKENCODINGS = [ # _codecs_cn @@ -205,6 +209,24 @@ class Test_IncrementalEncoder(unittest.TestCase): self.assertEqual(encoder.encode('\xff'), b'\\xff') self.assertEqual(encoder.encode('\n'), b'\n') + @support.cpython_only + def test_subinterp(self): + # bpo-42846: Test a CJK codec in a subinterpreter + import _testcapi + encoding = 'cp932' + text = "Python の開発は、1990 年ごろから開始されています。" + code = textwrap.dedent(""" + import codecs + encoding = %r + text = %r + encoder = codecs.getincrementalencoder(encoding)() + text2 = encoder.encode(text).decode(encoding) + if text2 != text: + raise ValueError(f"encoding issue: {text2!a} != {text!a}") + """) % (encoding, text) + res = _testcapi.run_in_subinterp(code) + self.assertEqual(res, 0) + class Test_IncrementalDecoder(unittest.TestCase): def test_dbcs(self): |