bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25142)
* test__xxsubinterpreters
* test_builtin
* test_doctest
* test_exceptions
* test_opcodes
* test_support
* test_argparse
* test_baseexception
* test_bdb
* test_bool
* test_asdl_parser
diff --git a/Lib/test/test__xxsubinterpreters.py b/Lib/test/test__xxsubinterpreters.py
index cf34fc3..7baea69 100644
--- a/Lib/test/test__xxsubinterpreters.py
+++ b/Lib/test/test__xxsubinterpreters.py
@@ -25,11 +25,11 @@ def _captured_script(script):
indented = script.replace('\n', '\n ')
wrapped = dedent(f"""
import contextlib
- with open({w}, 'w') as spipe:
+ with open({w}, 'w', encoding="utf-8") as spipe:
with contextlib.redirect_stdout(spipe):
{indented}
""")
- return wrapped, open(r)
+ return wrapped, open(r, encoding="utf-8")
def _run_output(interp, request, shared=None):
@@ -45,7 +45,7 @@ def _running(interp):
def run():
interpreters.run_string(interp, dedent(f"""
# wait for "signal"
- with open({r}) as rpipe:
+ with open({r}, encoding="utf-8") as rpipe:
rpipe.read()
"""))
@@ -54,7 +54,7 @@ def run():
yield
- with open(w, 'w') as spipe:
+ with open(w, 'w', encoding="utf-8") as spipe:
spipe.write('done')
t.join()
@@ -806,7 +806,7 @@ def f():
@unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
def test_fork(self):
import tempfile
- with tempfile.NamedTemporaryFile('w+') as file:
+ with tempfile.NamedTemporaryFile('w+', encoding="utf-8") as file:
file.write('')
file.flush()
@@ -816,7 +816,7 @@ def test_fork(self):
try:
os.fork()
except RuntimeError:
- with open('{file.name}', 'w') as out:
+ with open('{file.name}', 'w', encoding='utf-8') as out:
out.write('{expected}')
""")
interpreters.run_string(self.id, script)