mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-116417: Move limited C API unicode.c tests to _testlimitedcapi (#116993)
Split unicode.c tests of _testcapi into two parts: limited C API tests in _testlimitedcapi and non-limited C API tests in _testcapi. Update test_codecs.
This commit is contained in:
parent
1312094b39
commit
a557478987
12 changed files with 2082 additions and 2032 deletions
|
|
@ -13,9 +13,9 @@ from test import support
|
|||
from test.support import os_helper
|
||||
|
||||
try:
|
||||
import _testcapi
|
||||
import _testlimitedcapi
|
||||
except ImportError:
|
||||
_testcapi = None
|
||||
_testlimitedcapi = None
|
||||
try:
|
||||
import _testinternalcapi
|
||||
except ImportError:
|
||||
|
|
@ -2224,14 +2224,14 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
|
|||
"encoding=%r" % encoding)
|
||||
|
||||
@support.cpython_only
|
||||
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
|
||||
@unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
|
||||
def test_basics_capi(self):
|
||||
s = "abc123" # all codecs should be able to encode these
|
||||
for encoding in all_unicode_encodings:
|
||||
if encoding not in broken_unicode_with_stateful:
|
||||
# check incremental decoder/encoder (fetched via the C API)
|
||||
try:
|
||||
cencoder = _testcapi.codec_incrementalencoder(encoding)
|
||||
cencoder = _testlimitedcapi.codec_incrementalencoder(encoding)
|
||||
except LookupError: # no IncrementalEncoder
|
||||
pass
|
||||
else:
|
||||
|
|
@ -2240,7 +2240,7 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
|
|||
for c in s:
|
||||
encodedresult += cencoder.encode(c)
|
||||
encodedresult += cencoder.encode("", True)
|
||||
cdecoder = _testcapi.codec_incrementaldecoder(encoding)
|
||||
cdecoder = _testlimitedcapi.codec_incrementaldecoder(encoding)
|
||||
decodedresult = ""
|
||||
for c in encodedresult:
|
||||
decodedresult += cdecoder.decode(bytes([c]))
|
||||
|
|
@ -2251,12 +2251,12 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
|
|||
if encoding not in ("idna", "mbcs"):
|
||||
# check incremental decoder/encoder with errors argument
|
||||
try:
|
||||
cencoder = _testcapi.codec_incrementalencoder(encoding, "ignore")
|
||||
cencoder = _testlimitedcapi.codec_incrementalencoder(encoding, "ignore")
|
||||
except LookupError: # no IncrementalEncoder
|
||||
pass
|
||||
else:
|
||||
encodedresult = b"".join(cencoder.encode(c) for c in s)
|
||||
cdecoder = _testcapi.codec_incrementaldecoder(encoding, "ignore")
|
||||
cdecoder = _testlimitedcapi.codec_incrementaldecoder(encoding, "ignore")
|
||||
decodedresult = "".join(cdecoder.decode(bytes([c]))
|
||||
for c in encodedresult)
|
||||
self.assertEqual(decodedresult, s,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue