FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-143866: Verify return value of `pathlib.write_{bytes,text}` methods in tests (GH-143870) by miss-islington · Pull Request #144029 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 6 additions & 4 deletions Lib/test/test_pathlib/test_write.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading

Back | FazBrowse Home | New Git URL