8000 bpo-43651: PEP 597: Fix EncodingWarning in some tests by methane · Pull Request #25145 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43651: PEP 597: Fix EncodingWarning in some tests #25145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 4, 2021
Merged
Prev Previous commit
Next Next commit
Fix test_bz2
  • Loading branch information
methane committed Apr 2, 2021
commit d0b154b4a8829ed111da5fdc3eabc64deaf4b0d0
15 changes: 8 additions & 7 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,14 +922,14 @@ def test_text_modes(self):
for mode in ("wt", "xt"):
if mode == "xt":
unlink(self.filename)
with self.open(self.filename, mode) as f:
with self.open(self.filename, mode, encoding="ascii") as f:
f.write(text)
with open(self.filename, "rb") as f:
file_data = ext_decompress(f.read()).decode("ascii")
self.assertEqual(file_data, text_native_eol)
with self.open(self.filename, "rt") as f:
with self.open(self.filename, "rt", encoding="ascii") as f:
self.assertEqual(f.read(), text)
with self.open(self.filename, "at") as f:
with self.open(self.filename, "at", encoding="ascii") as f:
f.write(text)
with open(self.filename, "rb") as f:
file_data = ext_decompress(f.read()).decode("ascii")
Expand All @@ -938,7 +938,8 @@ def test_text_modes(self):
def test_x_mode(self):
for mode in ("x", "xb", "xt"):
unlink(self.filename)
with self.open(self.filename, mode) as f:
encoding = "utf-8" if "t" in mode else None
with self.open(self.filename, mode, encoding=encoding) as f:
pass
with self.assertRaises(FileExistsError):
with self.open(self.filename, mode) as f:
Expand All @@ -950,7 +951,7 @@ def test_fileobj(self):
with self.open(BytesIO(self.DATA), "rb") as f:
self.assertEqual(f.read(), self.TEXT)
text = self.TEXT.decode("ascii")
with self.open(BytesIO(self.DATA), "rt") as f:
with self.open(BytesIO(self.DATA), "rt", encoding="utf-8") as f:
self.assertEqual(f.read(), text)

def test_bad_params(self):
Expand Down Expand Up @@ -989,9 +990,9 @@ def test_encoding_error_handler(self):
def test_newline(self):
# Test with explicit newline (universal newline mode disabled).
text = self.TEXT.decode("ascii")
with self.open(self.filename, "wt", newline="\n") as f:
with self.open(self.filename, "wt", encoding="utf-8", newline="\n") as f:
f.write(text)
with self.open(self.filename, "rt", newline="\r") as f:
with self.open(self.filename, "rt", encoding="utf-8", newline="\r") as f:
self.assertEqual(f.readlines(), [text])


Expand Down
0