Skip to content

Commit ea18782

Browse files
miss-islingtonb9788213sobolevn
authored
[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 cb6a662) Co-authored-by: b9788213 <b9788213@gmail.com> Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 2147d3f commit ea18782

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/test/test_pathlib/test_write.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ def test_open_wb(self):
5959

6060
def test_write_bytes(self):
6161
p = self.root / 'fileA'
62-
p.write_bytes(b'abcdefg')
63-
self.assertEqual(self.ground.readbytes(p), b'abcdefg')
62+
data = b'abcdefg'
63+
self.assertEqual(len(data), p.write_bytes(data))
64+
self.assertEqual(self.ground.readbytes(p), data)
6465
# Check that trying to write str does not truncate the file.
6566
self.assertRaises(TypeError, p.write_bytes, 'somestr')
66-
self.assertEqual(self.ground.readbytes(p), b'abcdefg')
67+
self.assertEqual(self.ground.readbytes(p), data)
6768

6869
def test_write_text(self):
6970
p = self.root / 'fileA'
70-
p.write_text('äbcdefg', encoding='latin-1')
71+
data = 'äbcdefg'
72+
self.assertEqual(len(data), p.write_text(data, encoding='latin-1'))
7173
self.assertEqual(self.ground.readbytes(p), b'\xe4bcdefg')
7274
# Check that trying to write bytes does not truncate the file.
7375
self.assertRaises(TypeError, p.write_text, b'somebytes', encoding='utf-8')

0 commit comments

Comments
 (0)