summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-25 14:56:31 (GMT)
committerGitHub <noreply@github.com>2020-06-25 14:56:31 (GMT)
commit700cfa8c90a90016638bac13c4efd03786b2b2a0 (patch)
tree62994f7b8d6fccd910d5f65bd6cd49a4f72bf8ae /Lib/test
parent8ea6353f60625c96ce96588c70ff24a77f8c71f9 (diff)
downloadcpython-700cfa8c90a90016638bac13c4efd03786b2b2a0.zip
cpython-700cfa8c90a90016638bac13c4efd03786b2b2a0.tar.gz
cpython-700cfa8c90a90016638bac13c4efd03786b2b2a0.tar.bz2
bpo-41069: Make TESTFN and the CWD for tests containing non-ascii characters. (GH-21035)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/libregrtest/main.py1
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/support/os_helper.py21
-rw-r--r--Lib/test/test_binhex.py7
-rw-r--r--Lib/test/test_cgitb.py10
-rw-r--r--Lib/test/test_compileall.py6
-rw-r--r--Lib/test/test_embed.py4
-rw-r--r--Lib/test/test_fstring.py5
-rw-r--r--Lib/test/test_genericpath.py2
-rw-r--r--Lib/test/test_gzip.py18
-rw-r--r--Lib/test/test_msilib.py4
-rw-r--r--Lib/test/test_ntpath.py2
-rw-r--r--Lib/test/test_os.py6
-rw-r--r--Lib/test/test_pdb.py11
-rw-r--r--Lib/test/test_posixpath.py2
-rw-r--r--Lib/test/test_tarfile.py9
-rw-r--r--Lib/test/test_tools/test_pathfix.py8
-rw-r--r--Lib/test/test_trace.py9
-rw-r--r--Lib/test/test_urllib.py7
-rw-r--r--Lib/test/test_uu.py5
-rw-r--r--Lib/test/test_venv.py4
-rw-r--r--Lib/test/test_warnings/__init__.py6
22 files changed, 90 insertions, 59 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index 3f9771b..7675a97 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -597,6 +597,7 @@ class Regrtest:
test_cwd = 'test_python_worker_{}'.format(pid)
else:
test_cwd = 'test_python_{}'.format(pid)
+ test_cwd += support.FS_NONASCII
test_cwd = os.path.join(self.tmp_dir, test_cwd)
return test_cwd
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 5707d8e..f8f60fb 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -20,7 +20,7 @@ from .import_helper import (
forget, import_fresh_module, import_module, make_legacy_pyc,
modules_cleanup, modules_setup, unload)
from .os_helper import (
- FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_NONASCII,
+ FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_ASCII, TESTFN_NONASCII,
TESTFN_UNENCODABLE, TESTFN_UNDECODABLE,
TESTFN_UNICODE, can_symlink, can_xattr,
change_cwd, create_empty_file, fd_count,
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index d334702..d9807a1 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -13,16 +13,16 @@ import warnings
# Filename used for testing
if os.name == 'java':
# Jython disallows @ in module names
- TESTFN = '$test'
+ TESTFN_ASCII = '$test'
else:
- TESTFN = '@test'
+ TESTFN_ASCII = '@test'
# Disambiguate TESTFN for parallel testing, while letting it remain a valid
# module name.
-TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid())
+TESTFN_ASCII = "{}_{}_tmp".format(TESTFN_ASCII, os.getpid())
# TESTFN_UNICODE is a non-ascii filename
-TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f"
+TESTFN_UNICODE = TESTFN_ASCII + "-\xe0\xf2\u0258\u0141\u011f"
if sys.platform == 'darwin':
# In Mac OS X's VFS API file names are, by definition, canonically
# decomposed Unicode, encoded using UTF-8. See QA1173:
@@ -39,7 +39,7 @@ if os.name == 'nt':
if sys.getwindowsversion().platform >= 2:
# Different kinds of characters from various languages to minimize the
# probability that the whole name is encodable to MBCS (issue #9819)
- TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80"
+ TESTFN_UNENCODABLE = TESTFN_ASCII + "-\u5171\u0141\u2661\u0363\uDC80"
try:
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
@@ -56,7 +56,7 @@ elif sys.platform != 'darwin':
b'\xff'.decode(sys.getfilesystemencoding())
except UnicodeDecodeError:
# 0xff will be encoded using the surrogate character u+DCFF
- TESTFN_UNENCODABLE = TESTFN \
+ TESTFN_UNENCODABLE = TESTFN_ASCII \
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
else:
# File system encoding (eg. ISO-8859-* encodings) can encode
@@ -64,8 +64,8 @@ elif sys.platform != 'darwin':
pass
# FS_NONASCII: non-ASCII character encodable by os.fsencode(),
-# or None if there is no such character.
-FS_NONASCII = None
+# or an empty string if there is no such character.
+FS_NONASCII = ''
for character in (
# First try printable and common characters to have a readable filename.
# For each character, the encoding list are just example of encodings able
@@ -141,13 +141,14 @@ for name in (
try:
name.decode(sys.getfilesystemencoding())
except UnicodeDecodeError:
- TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
+ TESTFN_UNDECODABLE = os.fsencode(TESTFN_ASCII) + name
break
if FS_NONASCII:
- TESTFN_NONASCII = TESTFN + '-' + FS_NONASCII
+ TESTFN_NONASCII = TESTFN_ASCII + FS_NONASCII
else:
TESTFN_NONASCII = None
+TESTFN = TESTFN_NONASCII or TESTFN_ASCII
def make_bad_fd():
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py
index 8595532..591f32a 100644
--- a/Lib/test/test_binhex.py
+++ b/Lib/test/test_binhex.py
@@ -13,9 +13,10 @@ with support.check_warnings(('', DeprecationWarning)):
class BinHexTestCase(unittest.TestCase):
def setUp(self):
- self.fname1 = support.TESTFN + "1"
- self.fname2 = support.TESTFN + "2"
- self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
+ # binhex supports only file names encodable to Latin1
+ self.fname1 = support.TESTFN_ASCII + "1"
+ self.fname2 = support.TESTFN_ASCII + "2"
+ self.fname3 = support.TESTFN_ASCII + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
def tearDown(self):
support.unlink(self.fname1)
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py
index 8991bc1..bab152d 100644
--- a/Lib/test/test_cgitb.py
+++ b/Lib/test/test_cgitb.py
@@ -41,8 +41,9 @@ class TestCgitb(unittest.TestCase):
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(logdir=%s); '
- 'raise ValueError("Hello World")') % repr(tracedir))
- out = out.decode(sys.getfilesystemencoding())
+ 'raise ValueError("Hello World")') % repr(tracedir),
+ PYTHONIOENCODING='utf-8')
+ out = out.decode()
self.assertIn("ValueError", out)
self.assertIn("Hello World", out)
self.assertIn("<strong>&lt;module&gt;</strong>", out)
@@ -56,8 +57,9 @@ class TestCgitb(unittest.TestCase):
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(format="text", logdir=%s); '
- 'raise ValueError("Hello World")') % repr(tracedir))
- out = out.decode(sys.getfilesystemencoding())
+ 'raise ValueError("Hello World")') % repr(tracedir),
+ PYTHONIOENCODING='utf-8')
+ out = out.decode()
self.assertIn("ValueError", out)
self.assertIn("Hello World", out)
self.assertNotIn('<p>', out)
diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py
index b4061b7..3bbc681 100644
--- a/Lib/test/test_compileall.py
+++ b/Lib/test/test_compileall.py
@@ -456,13 +456,15 @@ class CommandLineTestsBase:
def assertRunOK(self, *args, **env_vars):
rc, out, err = script_helper.assert_python_ok(
- *self._get_run_args(args), **env_vars)
+ *self._get_run_args(args), **env_vars,
+ PYTHONIOENCODING='utf-8')
self.assertEqual(b'', err)
return out
def assertRunNotOK(self, *args, **env_vars):
rc, out, err = script_helper.assert_python_failure(
- *self._get_run_args(args), **env_vars)
+ *self._get_run_args(args), **env_vars,
+ PYTHONIOENCODING='utf-8')
return rc, out, err
def assertCompiled(self, fn):
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index e740fe8..fe47289 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -1349,7 +1349,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
returncode=1)
def test_audit_run_interactivehook(self):
- startup = os.path.join(self.oldcwd, support.TESTFN) + (support.FS_NONASCII or '') + ".py"
+ startup = os.path.join(self.oldcwd, support.TESTFN) + ".py"
with open(startup, "w", encoding="utf-8") as f:
print("import sys", file=f)
print("sys.__interactivehook__ = lambda: None", file=f)
@@ -1362,7 +1362,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
os.unlink(startup)
def test_audit_run_startup(self):
- startup = os.path.join(self.oldcwd, support.TESTFN) + (support.FS_NONASCII or '') + ".py"
+ startup = os.path.join(self.oldcwd, support.TESTFN) + ".py"
with open(startup, "w", encoding="utf-8") as f:
print("pass", file=f)
try:
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 9eb7ebe..7ffe01d 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -1055,8 +1055,9 @@ non-important content
file_path = os.path.join(cwd, 't.py')
with open(file_path, 'w') as f:
f.write('f"{a b}"') # This generates a SyntaxError
- _, _, stderr = assert_python_failure(file_path)
- self.assertIn(file_path, stderr.decode('utf-8'))
+ _, _, stderr = assert_python_failure(file_path,
+ PYTHONIOENCODING='ascii')
+ self.assertIn(file_path.encode('ascii', 'backslashreplace'), stderr)
def test_loop(self):
for i in range(1000):
diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py
index 9d5ac44..e7acbcd 100644
--- a/Lib/test/test_genericpath.py
+++ b/Lib/test/test_genericpath.py
@@ -534,7 +534,7 @@ class CommonTest(GenericTest):
class PathLikeTests(unittest.TestCase):
def setUp(self):
- self.file_name = support.TESTFN.lower()
+ self.file_name = support.TESTFN
self.file_path = FakePath(support.TESTFN)
self.addCleanup(support.unlink, self.file_name)
create_file(self.file_name, b"test_genericpath.PathLikeTests")
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 7833421..0f235d1 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -328,8 +328,15 @@ class TestGzip(BaseTest):
cmByte = fRead.read(1)
self.assertEqual(cmByte, b'\x08') # deflate
+ try:
+ expectedname = self.filename.encode('Latin-1') + b'\x00'
+ expectedflags = b'\x08' # only the FNAME flag is set
+ except UnicodeEncodeError:
+ expectedname = b''
+ expectedflags = b'\x00'
+
flagsByte = fRead.read(1)
- self.assertEqual(flagsByte, b'\x08') # only the FNAME flag is set
+ self.assertEqual(flagsByte, expectedflags)
mtimeBytes = fRead.read(4)
self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
@@ -344,9 +351,8 @@ class TestGzip(BaseTest):
# RFC 1952 specifies that this is the name of the input file, if any.
# However, the gzip module defaults to storing the name of the output
# file in this field.
- expected = self.filename.encode('Latin-1') + b'\x00'
- nameBytes = fRead.read(len(expected))
- self.assertEqual(nameBytes, expected)
+ nameBytes = fRead.read(len(expectedname))
+ self.assertEqual(nameBytes, expectedname)
# Since no other flags were set, the header ends here.
# Rather than process the compressed data, let's seek to the trailer.
@@ -358,6 +364,10 @@ class TestGzip(BaseTest):
isizeBytes = fRead.read(4)
self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
+ def test_metadata_ascii_name(self):
+ self.filename = support.TESTFN_ASCII
+ self.test_metadata()
+
def test_compresslevel_metadata(self):
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
# specifically, discussion of XFL in section 2.3.1
diff --git a/Lib/test/test_msilib.py b/Lib/test/test_msilib.py
index 153a8ac..4a233c3 100644
--- a/Lib/test/test_msilib.py
+++ b/Lib/test/test_msilib.py
@@ -1,13 +1,13 @@
""" Test suite for the code in msilib """
import os
import unittest
-from test.support import TESTFN, FS_NONASCII, import_module, unlink
+from test.support import TESTFN, import_module, unlink
msilib = import_module('msilib')
import msilib.schema
def init_database():
- path = TESTFN + (FS_NONASCII or '') + '.msi'
+ path = TESTFN + '.msi'
db = msilib.init_database(
path,
msilib.schema,
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 4a02db2..6f881f1 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -725,7 +725,7 @@ class PathLikeTests(NtpathTestCase):
path = ntpath
def setUp(self):
- self.file_name = support.TESTFN.lower()
+ self.file_name = support.TESTFN
self.file_path = FakePath(support.TESTFN)
self.addCleanup(support.unlink, self.file_name)
with open(self.file_name, 'xb', 0) as file:
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 7d4376a..ef2395d 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1174,7 +1174,7 @@ class WalkTests(unittest.TestCase):
os.makedirs(t2_path)
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path, tmp5_path:
- with open(path, "x") as f:
+ with open(path, "x", encoding='utf-8') as f:
f.write("I'm " + path + " and proud of it. Blame test_os.\n")
if support.can_symlink():
@@ -2360,7 +2360,7 @@ class Win32ListdirTests(unittest.TestCase):
file_name = 'FILE%d' % i
file_path = os.path.join(support.TESTFN, file_name)
os.makedirs(dir_path)
- with open(file_path, 'w') as f:
+ with open(file_path, 'w', encoding='utf-8') as f:
f.write("I'm %s and proud of it. Blame test_os.\n" % file_path)
self.created_paths.extend([dir_name, file_name])
self.created_paths.sort()
@@ -3738,7 +3738,7 @@ class PathTConverterTests(unittest.TestCase):
if os.name == 'nt':
bytes_fspath = bytes_filename = None
else:
- bytes_filename = support.TESTFN.encode('ascii')
+ bytes_filename = os.fsencode(support.TESTFN)
bytes_fspath = FakePath(bytes_filename)
fd = os.open(FakePath(str_filename), os.O_WRONLY|os.O_CREAT)
self.addCleanup(support.unlink, support.TESTFN)
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 1e8b12a..65bca29 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1198,6 +1198,7 @@ class PdbTestCase(unittest.TestCase):
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
+ env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
) as proc:
stdout, stderr = proc.communicate(str.encode(commands))
stdout = stdout and bytes.decode(stdout)
@@ -1353,10 +1354,11 @@ def bœr():
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
+ env={**os.environ, 'PYTHONIOENCODING': 'utf-8'}
)
self.addCleanup(proc.stdout.close)
stdout, stderr = proc.communicate(b'cont\n')
- self.assertNotIn('Error', stdout.decode(),
+ self.assertNotIn(b'Error', stdout,
"Got an error running test script under PDB")
def test_issue36250(self):
@@ -1382,10 +1384,11 @@ def bœr():
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.STDOUT,
+ env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
)
self.addCleanup(proc.stdout.close)
stdout, stderr = proc.communicate(b'cont\ncont\n')
- self.assertNotIn('Error', stdout.decode(),
+ self.assertNotIn(b'Error', stdout,
"Got an error running test script under PDB")
def test_issue16180(self):
@@ -1425,8 +1428,8 @@ def bœr():
)
with proc:
stdout, stderr = proc.communicate(b'q\n')
- self.assertNotIn("NameError: name 'invalid' is not defined",
- stdout.decode())
+ self.assertNotIn(b"NameError: name 'invalid' is not defined",
+ stdout)
finally:
if save_home is not None:
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 4d3d897..18819a5 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -627,7 +627,7 @@ class PathLikeTests(unittest.TestCase):
path = posixpath
def setUp(self):
- self.file_name = support.TESTFN.lower()
+ self.file_name = support.TESTFN
self.file_path = FakePath(support.TESTFN)
self.addCleanup(support.unlink, self.file_name)
with open(self.file_name, 'xb', 0) as file:
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index be66f1f..d60d35b 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -2305,7 +2305,8 @@ class CommandLineTest(unittest.TestCase):
def test_test_command_verbose(self):
for tar_name in testtarnames:
for opt in '-v', '--verbose':
- out = self.tarfilecmd(opt, '-t', tar_name)
+ out = self.tarfilecmd(opt, '-t', tar_name,
+ PYTHONIOENCODING='utf-8')
self.assertIn(b'is a tar archive.\n', out)
def test_test_command_invalid_file(self):
@@ -2376,7 +2377,8 @@ class CommandLineTest(unittest.TestCase):
'and-utf8-bom-sig-only.txt')]
for opt in '-v', '--verbose':
try:
- out = self.tarfilecmd(opt, '-c', tmpname, *files)
+ out = self.tarfilecmd(opt, '-c', tmpname, *files,
+ PYTHONIOENCODING='utf-8')
self.assertIn(b' file created.', out)
with tarfile.open(tmpname) as tar:
tar.getmembers()
@@ -2434,7 +2436,8 @@ class CommandLineTest(unittest.TestCase):
for opt in '-v', '--verbose':
try:
with support.temp_cwd(tarextdir):
- out = self.tarfilecmd(opt, '-e', tmpname)
+ out = self.tarfilecmd(opt, '-e', tmpname,
+ PYTHONIOENCODING='utf-8')
self.assertIn(b' file is extracted.', out)
finally:
support.rmtree(tarextdir)
diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py
index 8b41930..03ed29d 100644
--- a/Lib/test/test_tools/test_pathfix.py
+++ b/Lib/test/test_tools/test_pathfix.py
@@ -30,16 +30,18 @@ class TestPathfixFunctional(unittest.TestCase):
with open(filename, 'w', encoding='utf8') as f:
f.write(f'{shebang}\n' + 'print("Hello world")\n')
+ encoding = sys.getfilesystemencoding()
proc = subprocess.run(
[sys.executable, self.script,
*pathfix_flags, '-n', pathfix_arg],
- capture_output=True, text=1)
+ env={**os.environ, 'PYTHONIOENCODING': encoding},
+ capture_output=True)
if stdout == '' and proc.returncode == 0:
stdout = f'{filename}: updating\n'
self.assertEqual(proc.returncode, exitcode, proc)
- self.assertEqual(proc.stdout, stdout, proc)
- self.assertEqual(proc.stderr, stderr, proc)
+ self.assertEqual(proc.stdout.decode(encoding), stdout.replace('\n', os.linesep), proc)
+ self.assertEqual(proc.stderr.decode(encoding), stderr.replace('\n', os.linesep), proc)
with open(filename, 'r', encoding='utf8') as f:
output = f.read()
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 7cda546..89d4637 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -488,7 +488,8 @@ class TestCommandLine(unittest.TestCase):
with open(TESTFN, 'w') as fd:
self.addCleanup(unlink, TESTFN)
fd.write("a = 1\n")
- status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
+ status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN,
+ PYTHONIOENCODING='utf-8')
self.assertIn(b'functions called:', stdout)
def test_sys_argv_list(self):
@@ -498,7 +499,8 @@ class TestCommandLine(unittest.TestCase):
fd.write("print(type(sys.argv))\n")
status, direct_stdout, stderr = assert_python_ok(TESTFN)
- status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
+ status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN,
+ PYTHONIOENCODING='utf-8')
self.assertIn(direct_stdout.strip(), trace_stdout)
def test_count_and_summary(self):
@@ -517,7 +519,8 @@ class TestCommandLine(unittest.TestCase):
for i in range(10):
f()
"""))
- status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename)
+ status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename,
+ PYTHONIOENCODING='utf-8')
stdout = stdout.decode()
self.assertEqual(status, 0)
self.assertIn('lines cov% module (path)', stdout)
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index ebeb9a0..68bb49e 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -151,7 +151,8 @@ class urlopen_FileTests(unittest.TestCase):
finally:
f.close()
self.pathname = support.TESTFN
- self.returned_obj = urlopen("file:%s" % self.pathname)
+ self.quoted_pathname = urllib.parse.quote(self.pathname)
+ self.returned_obj = urlopen("file:%s" % self.quoted_pathname)
def tearDown(self):
"""Shut down the open object"""
@@ -198,7 +199,7 @@ class urlopen_FileTests(unittest.TestCase):
self.assertIsInstance(self.returned_obj.headers, email.message.Message)
def test_url(self):
- self.assertEqual(self.returned_obj.url, self.pathname)
+ self.assertEqual(self.returned_obj.url, self.quoted_pathname)
def test_status(self):
self.assertIsNone(self.returned_obj.status)
@@ -207,7 +208,7 @@ class urlopen_FileTests(unittest.TestCase):
self.assertIsInstance(self.returned_obj.info(), email.message.Message)
def test_geturl(self):
- self.assertEqual(self.returned_obj.geturl(), self.pathname)
+ self.assertEqual(self.returned_obj.geturl(), self.quoted_pathname)
def test_getcode(self):
self.assertIsNone(self.returned_obj.getcode())
diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py
index e229e92..753b31e 100644
--- a/Lib/test/test_uu.py
+++ b/Lib/test/test_uu.py
@@ -174,8 +174,9 @@ class UUStdIOTest(unittest.TestCase):
class UUFileTest(unittest.TestCase):
def setUp(self):
- self.tmpin = os_helper.TESTFN + "i"
- self.tmpout = os_helper.TESTFN + "o"
+ # uu.encode() supports only ASCII file names
+ self.tmpin = os_helper.TESTFN_ASCII + "i"
+ self.tmpout = os_helper.TESTFN_ASCII + "o"
self.addCleanup(os_helper.unlink, self.tmpin)
self.addCleanup(os_helper.unlink, self.tmpout)
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index d3191ed..ca003d5 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -80,8 +80,8 @@ class BaseTest(unittest.TestCase):
def get_env_file(self, *args):
return os.path.join(self.env_dir, *args)
- def get_text_file_contents(self, *args):
- with open(self.get_env_file(*args), 'r') as f:
+ def get_text_file_contents(self, *args, encoding='utf-8'):
+ with open(self.get_env_file(*args), 'r', encoding=encoding) as f:
result = f.read()
return result
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index 65d0b55..dcc0ea8 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -940,8 +940,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
"""))
def run(*args):
- res = assert_python_ok(*args)
- stderr = res.err.decode('ascii', 'replace')
+ res = assert_python_ok(*args, PYTHONIOENCODING='utf-8')
+ stderr = res.err.decode('utf-8', 'replace')
stderr = '\n'.join(stderr.splitlines())
# normalize newlines
@@ -1198,7 +1198,7 @@ class EnvironmentVariableTests(BaseTest):
@unittest.skipUnless(sys.getfilesystemencoding() != 'ascii',
'requires non-ascii filesystemencoding')
def test_nonascii(self):
- PYTHONWARNINGS="ignore:DeprecationWarning" + (support.FS_NONASCII or '')
+ PYTHONWARNINGS="ignore:DeprecationWarning" + support.FS_NONASCII
rc, stdout, stderr = assert_python_ok("-c",
"import sys; sys.stdout.write(str(sys.warnoptions))",
PYTHONIOENCODING="utf-8",