Skip to content

Commit e0ba4e7

Browse files
committed
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. (cherry picked from commit 35bdbca)
1 parent 7c5f4eb commit e0ba4e7

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
@@ -292,6 +292,7 @@ def test_fromkindanddata(self):
292292

293293
# Test invalid UCS-4 string. Create an invalid string in release mode,
294294
# or raise SystemError in debug mode.
295+
built_with_assert = support.built_with_c_assertions()
295296
for invalid_char in (INVALID_CHAR, MAX_INVALID_CHAR):
296297
with self.subTest(invalid_char=invalid_char):
297298
# Test single character
@@ -302,9 +303,12 @@ def test_fromkindanddata(self):
302303
s = 'valid'.encode(enc4) + ucs4_char
303304
if support.Py_DEBUG:
304305
self.assertRaises(SystemError, fromkindanddata, 4, s)
305-
else:
306+
elif not built_with_assert :
306307
result = fromkindanddata(4, s)
307308
assert_invalid_string(self, result)
309+
else:
310+
# PyUnicode_FromKindAndData() fails with an assertion error
311+
pass
308312

309313
@support.cpython_only
310314
@unittest.skipIf(_testlimitedcapi is None, 'need _testlimitedcapi module')
@@ -1994,6 +1998,7 @@ def test_ucs4(self):
19941998

19951999
# Invalid UCS-4 characters. Create an invalid string in release mode,
19962000
# or raise SystemError in debug mode.
2001+
built_with_assert = support.built_with_c_assertions()
19972002
writer = self.create_writer(0)
19982003
for invalid_char in (INVALID_CHAR, MAX_INVALID_CHAR):
19992004
with self.subTest(invalid_char=invalid_char):
@@ -2013,9 +2018,12 @@ def test_ucs4(self):
20132018

20142019
if support.Py_DEBUG:
20152020
self.assertEqual(writer.finish(), '')
2016-
else:
2021+
elif not built_with_assert:
20172022
result = writer.finish()
20182023
assert_invalid_string(self, result)
2024+
else:
2025+
# PyUnicodeWriter_Finish() fails with an assertion error
2026+
pass
20192027

20202028
# Invalid size
20212029
writer = self.create_writer(0)

0 commit comments

Comments
 (0)