Skip to content

Commit 35bdbca

Browse files
authored
gh-158445: Skip invalid UCS-4 tests if Python is built with assertions (#158604)
If Python is built in release mode with assertions, PyUnicode_FromKindAndData() and PyUnicodeWriter_Finish() fail with an assertion error on invalid characters.
1 parent a831abb commit 35bdbca

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎Lib/test/test_capi/test_unicode.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def test_fromkindanddata(self):
315315

316316
# Test invalid UCS-4 string. Create an invalid string in release mode,
317317
# or raise SystemError in debug mode.
318+
built_with_assert = support.built_with_c_assertions()
318319
for invalid_char in (INVALID_CHAR, MAX_INVALID_CHAR):
319320
with self.subTest(invalid_char=invalid_char):
320321
# Test single character
@@ -325,9 +326,12 @@ def test_fromkindanddata(self):
325326
s = 'valid'.encode(enc4) + ucs4_char
326327
if support.Py_DEBUG:
327328
self.assertRaises(SystemError, fromkindanddata, 4, s)
328-
else:
329+
elif not built_with_assert :
329330
result = fromkindanddata(4, s)
330331
assert_invalid_string(self, result)
332+
else:
333+
# PyUnicode_FromKindAndData() fails with an assertion error
334+
pass
331335

332336
def test_substring(self):
333337
"""Test PyUnicode_Substring()"""
@@ -2170,6 +2174,7 @@ def test_ucs4(self):
21702174

21712175
# Invalid UCS-4 characters. Create an invalid string in release mode,
21722176
# or raise SystemError in debug mode.
2177+
built_with_assert = support.built_with_c_assertions()
21732178
writer = self.create_writer(0)
21742179
for invalid_char in (INVALID_CHAR, MAX_INVALID_CHAR):
21752180
with self.subTest(invalid_char=invalid_char):
@@ -2189,9 +2194,12 @@ def test_ucs4(self):
21892194

21902195
if support.Py_DEBUG:
21912196
self.assertEqual(writer.finish(), '')
2192-
else:
2197+
elif not built_with_assert:
21932198
result = writer.finish()
21942199
assert_invalid_string(self, result)
2200+
else:
2201+
# PyUnicodeWriter_Finish() fails with an assertion error
2202+
pass
21952203

21962204
# Invalid size
21972205
writer = self.create_writer(0)

0 commit comments

Comments
 (0)