From c0be6fd42319ecc370e13a8fa67f52129e83d598 Mon Sep 17 00:00:00 2001 From: b9788213 Date: Mon, 19 Jan 2026 14:24:20 +0300 Subject: [PATCH] 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 --- Lib/test/test_pathlib/test_write.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_pathlib/test_write.py b/Lib/test/test_pathlib/test_write.py index b958490d0a834f..15054e804ec9fd 100644 --- a/Lib/test/test_pathlib/test_write.py +++ b/Lib/test/test_pathlib/test_write.py @@ -59,15 +59,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')