From 740db907a8bb51bcfb4e226968f112a4e3bdc1bb Mon Sep 17 00:00:00 2001 From: Bera Date: Tue, 20 Jan 2026 21:34:43 +0300 Subject: [PATCH] [3.13] gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870) (#144078) (cherry picked from commit cb6a662bb0f7a9da9d4ba9dda820053f8d54a9f8) Co-authored-by: sobolevn --- Lib/test/test_pathlib/test_pathlib_abc.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py index d9e51c0e3d64..170511a26daa 100644 --- a/Lib/test/test_pathlib/test_pathlib_abc.py +++ b/Lib/test/test_pathlib/test_pathlib_abc.py @@ -1630,20 +1630,22 @@ class DummyPathTest(DummyPurePathTest): def test_read_write_bytes(self): p = self.cls(self.base) - (p / 'fileA').write_bytes(b'abcdefg') - self.assertEqual((p / 'fileA').read_bytes(), b'abcdefg') + data = b'abcdefg' + self.assertEqual(len(data), (p / 'fileA').write_bytes(data)) + self.assertEqual((p / 'fileA').read_bytes(), data) # Check that trying to write str does not truncate the file. self.assertRaises(TypeError, (p / 'fileA').write_bytes, 'somestr') - self.assertEqual((p / 'fileA').read_bytes(), b'abcdefg') + self.assertEqual((p / 'fileA').read_bytes(), data) def test_read_write_text(self): p = self.cls(self.base) - (p / 'fileA').write_text('äbcdefg', encoding='latin-1') + data = 'äbcdefg' + self.assertEqual(len(data), (p / 'fileA').write_text(data, encoding='latin-1')) self.assertEqual((p / 'fileA').read_text( encoding='utf-8', errors='ignore'), 'bcdefg') # Check that trying to write bytes does not truncate the file. self.assertRaises(TypeError, (p / 'fileA').write_text, b'somebytes') - self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), 'äbcdefg') + self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), data) def test_read_text_with_newlines(self): p = self.cls(self.base) -- 2.47.3