https://github.com/python/cpython/commit/cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8
commit: cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8
branch: main
author: b9788213 <[email protected]>
committer: sobolevn <[email protected]>
date: 2026-01-19T14:24:20+03:00
summary:

gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests 
(#143870)

Co-authored-by: sobolevn <[email protected]>

files:
M Lib/test/test_pathlib/test_write.py

diff --git a/Lib/test/test_pathlib/test_write.py 
b/Lib/test/test_pathlib/test_write.py
index c9c1d64656c9be..fa2a81a47b33dc 100644
--- a/Lib/test/test_pathlib/test_write.py
+++ b/Lib/test/test_pathlib/test_write.py
@@ -65,15 +65,17 @@ def test_open_wb(self):
 
     def test_write_bytes(self):
         p = self.root / 'fileA'
-        p.write_bytes(b'abcdefg')
-        self.assertEqual(self.ground.readbytes(p), b'abcdefg')
+        data = b'abcdefg'
+        self.assertEqual(len(data), p.write_bytes(data))
+        self.assertEqual(self.ground.readbytes(p), data)
         # Check that trying to write str does not truncate the file.
         self.assertRaises(TypeError, p.write_bytes, 'somestr')
-        self.assertEqual(self.ground.readbytes(p), b'abcdefg')
+        self.assertEqual(self.ground.readbytes(p), data)
 
     def test_write_text(self):
         p = self.root / 'fileA'
-        p.write_text('äbcdefg', encoding='latin-1')
+        data = 'äbcdefg'
+        self.assertEqual(len(data), p.write_text(data, encoding='latin-1'))
         self.assertEqual(self.ground.readbytes(p), b'\xe4bcdefg')
         # Check that trying to write bytes does not truncate the file.
         self.assertRaises(TypeError, p.write_text, b'somebytes', 
encoding='utf-8')

_______________________________________________
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]

Reply via email to