mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
GH-128520: pathlib ABCs tests: use explicit text encoding (#133105)
Follow-up to fbffd70
. Set `encoding='utf-8'` when reading and writing text
in the tests for the private pathlib ABCs, which allows the tests to run
with `-W error -X warn_default_encoding`
This commit is contained in:
parent
606003ffa9
commit
336322b341
4 changed files with 13 additions and 13 deletions
|
@ -32,7 +32,7 @@ class ReadTestBase:
|
|||
|
||||
def test_open_r(self):
|
||||
p = self.root / 'fileA'
|
||||
with magic_open(p, 'r') as f:
|
||||
with magic_open(p, 'r', encoding='utf-8') as f:
|
||||
self.assertIsInstance(f, io.TextIOBase)
|
||||
self.assertEqual(f.read(), 'this is file A\n')
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ReadTestBase:
|
|||
|
||||
def test_read_text(self):
|
||||
p = self.root / 'fileA'
|
||||
self.assertEqual(p.read_text(), 'this is file A\n')
|
||||
self.assertEqual(p.read_text(encoding='utf-8'), 'this is file A\n')
|
||||
q = self.root / 'abc'
|
||||
self.ground.create_file(q, b'\xe4bcdefg')
|
||||
self.assertEqual(q.read_text(encoding='latin-1'), 'äbcdefg')
|
||||
|
@ -81,11 +81,11 @@ class ReadTestBase:
|
|||
p = self.root / 'abc'
|
||||
self.ground.create_file(p, b'abcde\r\nfghlk\n\rmnopq')
|
||||
# Check that `\n` character change nothing
|
||||
self.assertEqual(p.read_text(newline='\n'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual(p.read_text(encoding='utf-8', newline='\n'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
# Check that `\r` character replaces `\n`
|
||||
self.assertEqual(p.read_text(newline='\r'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual(p.read_text(encoding='utf-8', newline='\r'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
# Check that `\r\n` character replaces `\n`
|
||||
self.assertEqual(p.read_text(newline='\r\n'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
self.assertEqual(p.read_text(encoding='utf-8', newline='\r\n'), 'abcde\r\nfghlk\n\rmnopq')
|
||||
|
||||
def test_iterdir(self):
|
||||
expected = ['dirA', 'dirB', 'dirC', 'fileA']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue