mirror of
https://github.com/python/cpython.git
synced 2025-09-22 08:23:36 +00:00
gh-110745: add a newline argument to pathlib.Path.read_text (#110880)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
d857d5331a
commit
9d70831cb7
4 changed files with 22 additions and 3 deletions
|
@ -1878,6 +1878,21 @@ class DummyPathTest(unittest.TestCase):
|
|||
self.assertRaises(TypeError, (p / 'fileA').write_text, b'somebytes')
|
||||
self.assertEqual((p / 'fileA').read_text(encoding='latin-1'), 'äbcdefg')
|
||||
|
||||
def test_read_text_with_newlines(self):
|
||||
p = self.cls(BASE)
|
||||
# Check that `\n` character change nothing
|
||||
(p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual((p / 'fileA').read_text(newline='\n'),
|
||||
'abcde\r\nfghlk\n\rmnopq')
|
||||
# Check that `\r` character replaces `\n`
|
||||
(p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual((p / 'fileA').read_text(newline='\r'),
|
||||
'abcde\r\nfghlk\n\rmnopq')
|
||||
# Check that `\r\n` character replaces `\n`
|
||||
(p / 'fileA').write_bytes(b'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual((p / 'fileA').read_text(newline='\r\n'),
|
||||
'abcde\r\nfghlk\n\rmnopq')
|
||||
|
||||
def test_write_text_with_newlines(self):
|
||||
p = self.cls(BASE)
|
||||
# Check that `\n` character change nothing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue