8000 gh-111495: Add tests for `PyCodec_*` C API by picnixz · Pull Request #123343 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111495: Add tests for PyCodec_* C API #123343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Sep 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ce7c135
add tests for C API `codecs`
picnixz Aug 26, 2024
f9e350a
add Python tests for `_codecs`
picnixz Aug 26, 2024
15b6811
fix size bug
picnixz Aug 26, 2024
8048ae1
rename test class
picnixz Aug 26, 2024
8487b46
Revert "fix size bug"
picnixz Sep 25, 2024
2dbe09a
Merge branch 'main' into test/c-api-codec-111495
picnixz Sep 25, 2024
0097f2a
Disable tests that are known to crash.
picnixz Sep 25, 2024
303b13c
address Victor's review
picnixz Sep 25, 2024
4f474dd
update tests to reflect user errors
picnixz Sep 25, 2024
d49743c
Merge remote-tracking branch 'upstream/main' into test/c-api-codec-11…
picnixz Sep 27, 2024
87ee0d2
fix C API codec tests
picnixz Sep 27, 2024
6a36eb0
small hack to make the test suite correct
picnixz Sep 27, 2024
145b285
remove un-necessary imports
picnixz Sep 28, 2024
dc9af16
Merge remote-tracking branch 'upstream/main' into test/c-api-codec-11…
picnixz Sep 29, 2024
7be1f55
use `_codecs._unregister_error` to cleanup test state
picnixz Sep 29, 2024
f72be5c
indicate some semantics for NULL case being tested
picnixz Sep 29, 2024
4d02c6c
revert a cosmetic change
picnixz Sep 29, 2024
0f26ca7
Move `PyCodec_NameReplaceErrors` test to the `_testlimitedcapi` module
picnixz Sep 29, 2024
1399779
add comment for why we do not test `_Py 10000 Codec_UnregisterError`
picnixz Sep 29, 2024
914151e
update a comment
picnixz Sep 29, 2024
8dd7e8d
revert one cosmetic change
picnixz Sep 29, 2024
1e6a5ce
Fix Windows compilation
picnixz Sep 29, 2024
2ba5f03
address Victor's review
picnixz Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
address Victor's review
  • Loading branch information
picnixz committed Sep 29, 2024
commit 2ba5f031ed47eea1058f700e15a52046eb5cf37c
39 changes: 20 additions & 19 deletions Lib/test/test_capi/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ class CAPICodecs(unittest.TestCase):
def setUp(self):
# Encoding names are normalized internally by converting them
# to lowercase and their hyphens are replaced by underscores.
self.encoding_name = f'codec_reversed_{id(self)}'
self.encoding_name = 'test.test_capi.test_codecs.codec_reversed'
# Make sure that our custom codec is not already registered (that
# way we know whether we correctly unregistered the custom codec
# after a test or not).
Expand Down Expand Up @@ -658,12 +658,13 @@ def test_codec_decode(self):
self.assertRaises(UnicodeDecodeError, decode, b, 'ascii', NULL)
self.assertEqual(decode(b, 'ascii', 'replace'), 'a' + '\ufffd'*9)

# _codecs.decode() only reports unknown errors policy when they are
# used; this is different from PyUnicode_Decode() which checks that
# both the encoding and the errors policy are recognized before even
# attempting to call the decoder.
self.assertEqual(decode(b'', 'utf-8', 'unknown-errors-policy'), '')
self.assertEqual(decode(b'a', 'utf-8', 10000 'unknown-errors-policy'), 'a')
# _codecs.decode() only reports an unknown error handling name when
# the corresponding error handling function is used; this difers
# from PyUnicode_Decode() which checks that both the encoding and
# the error handling name are recognized before even attempting to
# call the decoder.
self.assertEqual(decode(b'', 'utf-8', 'unknown-error-handler'), '')
self.assertEqual(decode(b'a', 'utf-8', 'unknown-error-handler'), 'a')

self.assertRaises(TypeError, decode, NULL, 'ascii', 'strict')
with self.assertRaisesRegex(TypeError, BAD_ARGUMENT):
Expand Down Expand Up @@ -695,9 +696,9 @@ def test_codec_incremental_encoder(self):
with self.use_custom_encoder():
encoding = self.encoding_name

for policy in ['strict', NULL]:
with self.subTest(policy=policy):
encoder = codec_incremental_encoder(encoding, policy)
for errors in ['strict', NULL]:
with self.subTest(errors):
encoder = codec_incremental_encoder(encoding, errors)
self.assertIsInstance(encoder, self.codec_info.incrementalencoder)

with self.assertRaisesRegex(TypeError, BAD_ARGUMENT):
Expand All @@ -709,9 +710,9 @@ def test_codec_incremental_decoder(self):
with self.use_custom_encoder():
encoding = self.encoding_name

for policy in ['strict', NULL]:
with self.subTest(policy=policy):
decoder = codec_incremental_decoder(encoding, policy)
for errors in ['strict', NULL]:
with self.subTest(errors):
decoder = codec_incremental_decoder(encoding, errors)
self.assertIsInstance(decoder, self.codec_info.incrementaldecoder)

with self.assertRaisesRegex(TypeError, BAD_ARGUMENT):
Expand All @@ -722,9 +723,9 @@ def test_codec_stream_reader(self):

with self.use_custom_encoder():
encoding, stream = self.encoding_name, io.StringIO()
for policy in ['strict', NULL]:
with self.subTest(policy=policy):
writer = codec_stream_reader(encoding, stream, policy)
for errors in ['strict', NULL]:
with self.subTest(errors):
writer = codec_stream_reader(encoding, stream, errors)
self.assertIsInstance(writer, self.codec_info.streamreader)

with self.assertRaisesRegex(TypeError, BAD_ARGUMENT):
Expand All @@ -735,9 +736,9 @@ def test_codec_stream_writer(self):

with self.use_custom_encoder():
encoding, stream = self.encoding_name, io.StringIO()
for policy in ['strict', NULL]:
with self.subTest(policy=policy):
writer = codec_stream_writer(encoding, stream, policy)
for errors in ['strict', NULL]:
with self.subTest(errors):
writer = codec_stream_writer(encoding, stream, errors)
self.assertIsInstance(writer, self.codec_info.streamwriter)

with self.assertRaisesRegex(TypeError, BAD_ARGUMENT):
Expand Down
Loading
0