]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 19 Jan 2026 11:50:54 +0000 (12:50 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Jan 2026 11:50:54 +0000 (11:50 +0000)
gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870)
(cherry picked from commit cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8)

Co-authored-by: b9788213 <b9788213@gmail.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
Lib/test/test_pathlib/test_write.py

index b958490d0a834f64c81eaa15c605b0bb3a6325f1..15054e804ec9fdf86c8b0b736b66242599579e92 100644 (file)
@@ -59,15 +59,17 @@ class WriteTestBase:
 
     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')