diff options
author | Inada Naoki <songofacandy@gmail.com> | 2021-04-06 04:02:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 04:02:22 (GMT) |
commit | 4663e5f39e9f872dcd69545f293e832d5855d084 (patch) | |
tree | e5c9eda76444f1f89c81bf1ecf05451de8ee4f01 /Lib/test/test_lzma.py | |
parent | fb78692f2ad5ee4747f13a73943fbf134b637669 (diff) | |
download | cpython-4663e5f39e9f872dcd69545f293e832d5855d084.zip cpython-4663e5f39e9f872dcd69545f293e832d5855d084.tar.gz cpython-4663e5f39e9f872dcd69545f293e832d5855d084.tar.bz2 |
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25190)
* Fix test_lzma
* Fix test_mailbox
* Fix test_mimetypes
* Fix test_posix
Diffstat (limited to 'Lib/test/test_lzma.py')
-rw-r--r-- | Lib/test/test_lzma.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index c2427f8..db20300 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -1250,14 +1250,14 @@ class OpenTestCase(unittest.TestCase): def test_text_modes(self): uncompressed = INPUT.decode("ascii") uncompressed_raw = uncompressed.replace("\n", os.linesep) - with lzma.open(BytesIO(COMPRESSED_XZ), "rt") as f: + with lzma.open(BytesIO(COMPRESSED_XZ), "rt", encoding="ascii") as f: self.assertEqual(f.read(), uncompressed) with BytesIO() as bio: - with lzma.open(bio, "wt") as f: + with lzma.open(bio, "wt", encoding="ascii") as f: f.write(uncompressed) file_data = lzma.decompress(bio.getvalue()).decode("ascii") self.assertEqual(file_data, uncompressed_raw) - with lzma.open(bio, "at") as f: + with lzma.open(bio, "at", encoding="ascii") as f: f.write(uncompressed) file_data = lzma.decompress(bio.getvalue()).decode("ascii") self.assertEqual(file_data, uncompressed_raw * 2) @@ -1334,17 +1334,18 @@ class OpenTestCase(unittest.TestCase): # Test with explicit newline (universal newline mode disabled). text = INPUT.decode("ascii") with BytesIO() as bio: - with lzma.open(bio, "wt", newline="\n") as f: + with lzma.open(bio, "wt", encoding="ascii", newline="\n") as f: f.write(text) bio.seek(0) - with lzma.open(bio, "rt", newline="\r") as f: + with lzma.open(bio, "rt", encoding="ascii", newline="\r") as f: self.assertEqual(f.readlines(), [text]) def test_x_mode(self): self.addCleanup(unlink, TESTFN) for mode in ("x", "xb", "xt"): unlink(TESTFN) - with lzma.open(TESTFN, mode): + encoding = "ascii" if "t" in mode else None + with lzma.open(TESTFN, mode, encoding=encoding): pass with self.assertRaises(FileExistsError): with lzma.open(TESTFN, mode): |