From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 19 Jan 2026 11:50:54 +0000 (+0100) Subject: [3.14] gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea18782814d9d81cff6a66ddf3c056bacbf3bae7;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870) (#144029) gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870) (cherry picked from commit cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8) Co-authored-by: b9788213 Co-authored-by: sobolevn --- diff --git a/Lib/test/test_pathlib/test_write.py b/Lib/test/test_pathlib/test_write.py index b958490d0a83..15054e804ec9 100644 --- a/Lib/test/test_pathlib/test_write.py +++ b/Lib/test/test_pathlib/test_write.py @@ -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')