From: b9788213 Date: Mon, 19 Jan 2026 11:24:20 +0000 (+0300) Subject: gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests ... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8;p=thirdparty%2FPython%2Fcpython.git gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (#143870) Co-authored-by: sobolevn --- diff --git a/Lib/test/test_pathlib/test_write.py b/Lib/test/test_pathlib/test_write.py index c9c1d64656c9..fa2a81a47b33 100644 --- a/Lib/test/test_pathlib/test_write.py +++ b/Lib/test/test_pathlib/test_write.py @@ -65,15 +65,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')