https://github.com/python/cpython/commit/044fe0b2e11b2cbdacbfc12ca34d9819d88457a1
commit: 044fe0b2e11b2cbdacbfc12ca34d9819d88457a1
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-05-22T07:28:44Z
summary:

[3.13] gh-131357: Add some extra tests for empty bytes and bytearray 
(GH-134458) (#134490)

gh-131357: Add some extra tests for empty bytes and bytearray (GH-134458)
(cherry picked from commit 7309eb60c077836b4b05a86ed23c710dbff737ec)

Co-authored-by: Sergey Miryanov <sergey.mirya...@gmail.com>

files:
M Lib/test/test_capi/test_bytearray.py
M Lib/test/test_capi/test_bytes.py

diff --git a/Lib/test/test_capi/test_bytearray.py 
b/Lib/test/test_capi/test_bytearray.py
index 699fc9d0589e1d..d5b164fc586fb3 100644
--- a/Lib/test/test_capi/test_bytearray.py
+++ b/Lib/test/test_capi/test_bytearray.py
@@ -66,6 +66,7 @@ def test_fromobject(self):
         # Test PyByteArray_FromObject()
         fromobject = _testlimitedcapi.bytearray_fromobject
 
+        self.assertEqual(fromobject(b''), bytearray(b''))
         self.assertEqual(fromobject(b'abc'), bytearray(b'abc'))
         self.assertEqual(fromobject(bytearray(b'abc')), bytearray(b'abc'))
         self.assertEqual(fromobject(ByteArraySubclass(b'abc')), 
bytearray(b'abc'))
@@ -115,6 +116,7 @@ def test_concat(self):
         self.assertEqual(concat(b'abc', bytearray(b'def')), 
bytearray(b'abcdef'))
         self.assertEqual(concat(bytearray(b'abc'), b''), bytearray(b'abc'))
         self.assertEqual(concat(b'', bytearray(b'def')), bytearray(b'def'))
+        self.assertEqual(concat(bytearray(b''), bytearray(b'')), 
bytearray(b''))
         self.assertEqual(concat(memoryview(b'xabcy')[1:4], b'def'),
                          bytearray(b'abcdef'))
         self.assertEqual(concat(b'abc', memoryview(b'xdefy')[1:4]),
@@ -150,6 +152,10 @@ def test_resize(self):
         self.assertEqual(resize(ba, 0), 0)
         self.assertEqual(ba, bytearray())
 
+        ba = bytearray(b'')
+        self.assertEqual(resize(ba, 0), 0)
+        self.assertEqual(ba, bytearray())
+
         ba = ByteArraySubclass(b'abcdef')
         self.assertEqual(resize(ba, 3), 0)
         self.assertEqual(ba, bytearray(b'abc'))
diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py
index fa9e0e8ed0fbca..35b725ae34a1ed 100644
--- a/Lib/test/test_capi/test_bytes.py
+++ b/Lib/test/test_capi/test_bytes.py
@@ -81,6 +81,7 @@ def test_fromobject(self):
         # Test PyBytes_FromObject()
         fromobject = _testlimitedcapi.bytes_fromobject
 
+        self.assertEqual(fromobject(b''), b'')
         self.assertEqual(fromobject(b'abc'), b'abc')
         self.assertEqual(fromobject(bytearray(b'abc')), b'abc')
         self.assertEqual(fromobject(BytesSubclass(b'abc')), b'abc')
@@ -138,6 +139,7 @@ def test_repr(self):
         # Test PyBytes_Repr()
         bytes_repr = _testlimitedcapi.bytes_repr
 
+        self.assertEqual(bytes_repr(b'', 0), r"""b''""")
         self.assertEqual(bytes_repr(b'''abc''', 0), r"""b'abc'""")
         self.assertEqual(bytes_repr(b'''abc''', 1), r"""b'abc'""")
         self.assertEqual(bytes_repr(b'''a'b"c"d''', 0), r"""b'a\'b"c"d'""")
@@ -197,6 +199,7 @@ def test_decodeescape(self):
         """Test PyBytes_DecodeEscape()"""
         decodeescape = _testlimitedcapi.bytes_decodeescape
 
+        self.assertEqual(decodeescape(b''), b'')
         self.assertEqual(decodeescape(b'abc'), b'abc')
         self.assertEqual(decodeescape(br'\t\n\r\x0b\x0c\x00\\\'\"'),
                          b'''\t\n\r\v\f\0\\'"''')

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to