diff options
author | Barney Gale <barney.gale@gmail.com> | 2025-04-28 20:18:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 20:18:56 +0100 |
commit | 336322b34137d90b0db19545c09a77f050ba8de0 (patch) | |
tree | 47c8efaea297dbe6e94f416b6490fbcfe9189fa8 /Lib/test/test_pathlib/test_read.py | |
parent | 606003ffa9e400cc22cc3b11f31118e2e24f688e (diff) | |
download | cpython-336322b34137d90b0db19545c09a77f050ba8de0.tar.gz cpython-336322b34137d90b0db19545c09a77f050ba8de0.zip |
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`
Diffstat (limited to 'Lib/test/test_pathlib/test_read.py')
-rw-r--r-- | Lib/test/test_pathlib/test_read.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib/test_read.py b/Lib/test/test_pathlib/test_read.py index 9bb5535a6eb..482203c290a 100644 --- a/Lib/test/test_pathlib/test_read.py +++ b/Lib/test/test_pathlib/test_read.py @@ -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'] |