gh-155742: Test PyBytesWriter_FinishWithSize() with negative size (#155783)

vstinner <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/b8e23da18a5ddd86f85f7654e3b4565c82623456
commit: b8e23da18a5ddd86f85f7654e3b4565c82623456
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-08-14T14:33:01+02:00
summary:

gh-155742: Test PyBytesWriter_FinishWithSize() with negative size (#155783)

Add test_finish_with_size() to test_capi.test_bytes.

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

diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py
index c591e986bbce35..d20e5016f969c2 100644
--- a/Lib/test/test_capi/test_bytes.py
+++ b/Lib/test/test_capi/test_bytes.py
@@ -315,10 +315,16 @@ def test_create(self):
         self.assertEqual(writer.get_size(), 3)
         self.assertEqual(writer.finish(), self.result_type(b'abc'))
 
+    def test_finish_with_size(self):
+        # Test PyBytesWriter_FinishWithSize()
         writer = self.create_writer(10, b'abc')
         self.assertEqual(writer.get_size(), 10)
         self.assertEqual(writer.finish_with_size(3), self.result_type(b'abc'))
 
+        writer = self.create_writer(3, b'abc')
+        with self.assertRaises(SystemError):
+            writer.finish_with_size(-3)
+
     def test_write_bytes(self):
          # Test PyBytesWriter_WriteBytes()
          writer = self.create_writer()

_______________________________________________
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]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.