https://github.com/python/cpython/commit/7f2de07808b13bd345855fec42ac6add2cfb3704
commit: 7f2de07808b13bd345855fec42ac6add2cfb3704
branch: 3.12
author: Nybblista <[email protected]>
committer: sobolevn <[email protected]>
date: 2025-03-23T17:43:12Z
summary:
[3.12] gh-131357: Add a set of asserts to test.test_capi.test_bytearray
(GH-131554) (#131629)
[3.12] gh-131357: Add a set of asserts to test.test_capi.test_bytearray
(#131554)
add a set of asserts to test.test_capi.test_bytearray
1. Assert empty bytearray object for PyByteArray_Check.
2. Assert empty bytearray object for PyByteArray_CheckExact.
3. Assert 0-size bytearray object for PyByteArray_Size.
4. Assert empty bytearray object for PyByteArray_AsString.
5. Assert concatenation of the bytearray object with itself for
PyByteArray_Concat.
(cherry picked from commit f3bf304c2799c31c045033f22db7eb8766a5f939)
files:
M Lib/test/test_capi/test_bytearray.py
diff --git a/Lib/test/test_capi/test_bytearray.py
b/Lib/test/test_capi/test_bytearray.py
index 833122c4e319d8..ad2192f46e9562 100644
--- a/Lib/test/test_capi/test_bytearray.py
+++ b/Lib/test/test_capi/test_bytearray.py
@@ -20,6 +20,7 @@ class CAPITest(unittest.TestCase):
def test_check(self):
# Test PyByteArray_Check()
check = _testcapi.bytearray_check
+ self.assertTrue(check(bytearray(b'')))
self.assertTrue(check(bytearray(b'abc')))
self.assertFalse(check(b'abc'))
self.assertTrue(check(ByteArraySubclass(b'abc')))
@@ -33,6 +34,7 @@ def test_check(self):
def test_checkexact(self):
# Test PyByteArray_CheckExact()
check = _testcapi.bytearray_checkexact
+ self.assertTrue(check(bytearray(b'')))
self.assertTrue(check(bytearray(b'abc')))
self.assertFalse(check(b'abc'))
self.assertFalse(check(ByteArraySubclass(b'abc')))
@@ -79,6 +81,7 @@ def test_size(self):
# Test PyByteArray_Size()
size = _testcapi.bytearray_size
+ self.assertEqual(size(bytearray(b'')), 0)
self.assertEqual(size(bytearray(b'abc')), 3)
self.assertEqual(size(ByteArraySubclass(b'abc')), 3)
@@ -90,6 +93,7 @@ def test_asstring(self):
"""Test PyByteArray_AsString()"""
asstring = _testcapi.bytearray_asstring
+ self.assertEqual(asstring(bytearray(b''), 1), b'\0')
self.assertEqual(asstring(bytearray(b'abc'), 4), b'abc\0')
self.assertEqual(asstring(ByteArraySubclass(b'abc'), 4), b'abc\0')
self.assertEqual(asstring(bytearray(b'abc\0def'), 8), b'abc\0def\0')
@@ -105,6 +109,7 @@ def test_concat(self):
ba = bytearray(b'abc')
self.assertEqual(concat(ba, b'def'), bytearray(b'abcdef'))
self.assertEqual(ba, b'abc')
+ self.assertEqual(concat(ba, ba), bytearray(b'abcabc'))
self.assertEqual(concat(b'abc', b'def'), bytearray(b'abcdef'))
self.assertEqual(concat(b'a\0b', b'c\0d'), bytearray(b'a\0bc\0d'))
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]