mirror of https://github.com/python/cpython
bpo-41069: Make TESTFN and the CWD for tests containing non-ascii characters. (GH-21035)
This commit is contained in:
parent
8ea6353f60
commit
700cfa8c90
|
@ -597,6 +597,7 @@ class Regrtest:
|
||||||
test_cwd = 'test_python_worker_{}'.format(pid)
|
test_cwd = 'test_python_worker_{}'.format(pid)
|
||||||
else:
|
else:
|
||||||
test_cwd = 'test_python_{}'.format(pid)
|
test_cwd = 'test_python_{}'.format(pid)
|
||||||
|
test_cwd += support.FS_NONASCII
|
||||||
test_cwd = os.path.join(self.tmp_dir, test_cwd)
|
test_cwd = os.path.join(self.tmp_dir, test_cwd)
|
||||||
return test_cwd
|
return test_cwd
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ from .import_helper import (
|
||||||
forget, import_fresh_module, import_module, make_legacy_pyc,
|
forget, import_fresh_module, import_module, make_legacy_pyc,
|
||||||
modules_cleanup, modules_setup, unload)
|
modules_cleanup, modules_setup, unload)
|
||||||
from .os_helper import (
|
from .os_helper import (
|
||||||
FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_NONASCII,
|
FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_ASCII, TESTFN_NONASCII,
|
||||||
TESTFN_UNENCODABLE, TESTFN_UNDECODABLE,
|
TESTFN_UNENCODABLE, TESTFN_UNDECODABLE,
|
||||||
TESTFN_UNICODE, can_symlink, can_xattr,
|
TESTFN_UNICODE, can_symlink, can_xattr,
|
||||||
change_cwd, create_empty_file, fd_count,
|
change_cwd, create_empty_file, fd_count,
|
||||||
|
|
|
@ -13,16 +13,16 @@ import warnings
|
||||||
# Filename used for testing
|
# Filename used for testing
|
||||||
if os.name == 'java':
|
if os.name == 'java':
|
||||||
# Jython disallows @ in module names
|
# Jython disallows @ in module names
|
||||||
TESTFN = '$test'
|
TESTFN_ASCII = '$test'
|
||||||
else:
|
else:
|
||||||
TESTFN = '@test'
|
TESTFN_ASCII = '@test'
|
||||||
|
|
||||||
# Disambiguate TESTFN for parallel testing, while letting it remain a valid
|
# Disambiguate TESTFN for parallel testing, while letting it remain a valid
|
||||||
# module name.
|
# 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 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':
|
if sys.platform == 'darwin':
|
||||||
# In Mac OS X's VFS API file names are, by definition, canonically
|
# In Mac OS X's VFS API file names are, by definition, canonically
|
||||||
# decomposed Unicode, encoded using UTF-8. See QA1173:
|
# decomposed Unicode, encoded using UTF-8. See QA1173:
|
||||||
|
@ -39,7 +39,7 @@ if os.name == 'nt':
|
||||||
if sys.getwindowsversion().platform >= 2:
|
if sys.getwindowsversion().platform >= 2:
|
||||||
# Different kinds of characters from various languages to minimize the
|
# Different kinds of characters from various languages to minimize the
|
||||||
# probability that the whole name is encodable to MBCS (issue #9819)
|
# 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:
|
try:
|
||||||
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
|
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
|
@ -56,7 +56,7 @@ elif sys.platform != 'darwin':
|
||||||
b'\xff'.decode(sys.getfilesystemencoding())
|
b'\xff'.decode(sys.getfilesystemencoding())
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# 0xff will be encoded using the surrogate character u+DCFF
|
# 0xff will be encoded using the surrogate character u+DCFF
|
||||||
TESTFN_UNENCODABLE = TESTFN \
|
TESTFN_UNENCODABLE = TESTFN_ASCII \
|
||||||
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
|
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
|
||||||
else:
|
else:
|
||||||
# File system encoding (eg. ISO-8859-* encodings) can encode
|
# File system encoding (eg. ISO-8859-* encodings) can encode
|
||||||
|
@ -64,8 +64,8 @@ elif sys.platform != 'darwin':
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# FS_NONASCII: non-ASCII character encodable by os.fsencode(),
|
# FS_NONASCII: non-ASCII character encodable by os.fsencode(),
|
||||||
# or None if there is no such character.
|
# or an empty string if there is no such character.
|
||||||
FS_NONASCII = None
|
FS_NONASCII = ''
|
||||||
for character in (
|
for character in (
|
||||||
# First try printable and common characters to have a readable filename.
|
# First try printable and common characters to have a readable filename.
|
||||||
# For each character, the encoding list are just example of encodings able
|
# For each character, the encoding list are just example of encodings able
|
||||||
|
@ -141,13 +141,14 @@ for name in (
|
||||||
try:
|
try:
|
||||||
name.decode(sys.getfilesystemencoding())
|
name.decode(sys.getfilesystemencoding())
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
|
TESTFN_UNDECODABLE = os.fsencode(TESTFN_ASCII) + name
|
||||||
break
|
break
|
||||||
|
|
||||||
if FS_NONASCII:
|
if FS_NONASCII:
|
||||||
TESTFN_NONASCII = TESTFN + '-' + FS_NONASCII
|
TESTFN_NONASCII = TESTFN_ASCII + FS_NONASCII
|
||||||
else:
|
else:
|
||||||
TESTFN_NONASCII = None
|
TESTFN_NONASCII = None
|
||||||
|
TESTFN = TESTFN_NONASCII or TESTFN_ASCII
|
||||||
|
|
||||||
|
|
||||||
def make_bad_fd():
|
def make_bad_fd():
|
||||||
|
|
|
@ -13,9 +13,10 @@ with support.check_warnings(('', DeprecationWarning)):
|
||||||
class BinHexTestCase(unittest.TestCase):
|
class BinHexTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.fname1 = support.TESTFN + "1"
|
# binhex supports only file names encodable to Latin1
|
||||||
self.fname2 = support.TESTFN + "2"
|
self.fname1 = support.TESTFN_ASCII + "1"
|
||||||
self.fname3 = support.TESTFN + "very_long_filename__very_long_filename__very_long_filename__very_long_filename__"
|
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):
|
def tearDown(self):
|
||||||
support.unlink(self.fname1)
|
support.unlink(self.fname1)
|
||||||
|
|
|
@ -41,8 +41,9 @@ class TestCgitb(unittest.TestCase):
|
||||||
rc, out, err = assert_python_failure(
|
rc, out, err = assert_python_failure(
|
||||||
'-c',
|
'-c',
|
||||||
('import cgitb; cgitb.enable(logdir=%s); '
|
('import cgitb; cgitb.enable(logdir=%s); '
|
||||||
'raise ValueError("Hello World")') % repr(tracedir))
|
'raise ValueError("Hello World")') % repr(tracedir),
|
||||||
out = out.decode(sys.getfilesystemencoding())
|
PYTHONIOENCODING='utf-8')
|
||||||
|
out = out.decode()
|
||||||
self.assertIn("ValueError", out)
|
self.assertIn("ValueError", out)
|
||||||
self.assertIn("Hello World", out)
|
self.assertIn("Hello World", out)
|
||||||
self.assertIn("<strong><module></strong>", out)
|
self.assertIn("<strong><module></strong>", out)
|
||||||
|
@ -56,8 +57,9 @@ class TestCgitb(unittest.TestCase):
|
||||||
rc, out, err = assert_python_failure(
|
rc, out, err = assert_python_failure(
|
||||||
'-c',
|
'-c',
|
||||||
('import cgitb; cgitb.enable(format="text", logdir=%s); '
|
('import cgitb; cgitb.enable(format="text", logdir=%s); '
|
||||||
'raise ValueError("Hello World")') % repr(tracedir))
|
'raise ValueError("Hello World")') % repr(tracedir),
|
||||||
out = out.decode(sys.getfilesystemencoding())
|
PYTHONIOENCODING='utf-8')
|
||||||
|
out = out.decode()
|
||||||
self.assertIn("ValueError", out)
|
self.assertIn("ValueError", out)
|
||||||
self.assertIn("Hello World", out)
|
self.assertIn("Hello World", out)
|
||||||
self.assertNotIn('<p>', out)
|
self.assertNotIn('<p>', out)
|
||||||
|
|
|
@ -456,13 +456,15 @@ class CommandLineTestsBase:
|
||||||
|
|
||||||
def assertRunOK(self, *args, **env_vars):
|
def assertRunOK(self, *args, **env_vars):
|
||||||
rc, out, err = script_helper.assert_python_ok(
|
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)
|
self.assertEqual(b'', err)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def assertRunNotOK(self, *args, **env_vars):
|
def assertRunNotOK(self, *args, **env_vars):
|
||||||
rc, out, err = script_helper.assert_python_failure(
|
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
|
return rc, out, err
|
||||||
|
|
||||||
def assertCompiled(self, fn):
|
def assertCompiled(self, fn):
|
||||||
|
|
|
@ -1349,7 +1349,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
returncode=1)
|
returncode=1)
|
||||||
|
|
||||||
def test_audit_run_interactivehook(self):
|
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:
|
with open(startup, "w", encoding="utf-8") as f:
|
||||||
print("import sys", file=f)
|
print("import sys", file=f)
|
||||||
print("sys.__interactivehook__ = lambda: None", file=f)
|
print("sys.__interactivehook__ = lambda: None", file=f)
|
||||||
|
@ -1362,7 +1362,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
|
||||||
os.unlink(startup)
|
os.unlink(startup)
|
||||||
|
|
||||||
def test_audit_run_startup(self):
|
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:
|
with open(startup, "w", encoding="utf-8") as f:
|
||||||
print("pass", file=f)
|
print("pass", file=f)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1055,8 +1055,9 @@ non-important content
|
||||||
file_path = os.path.join(cwd, 't.py')
|
file_path = os.path.join(cwd, 't.py')
|
||||||
with open(file_path, 'w') as f:
|
with open(file_path, 'w') as f:
|
||||||
f.write('f"{a b}"') # This generates a SyntaxError
|
f.write('f"{a b}"') # This generates a SyntaxError
|
||||||
_, _, stderr = assert_python_failure(file_path)
|
_, _, stderr = assert_python_failure(file_path,
|
||||||
self.assertIn(file_path, stderr.decode('utf-8'))
|
PYTHONIOENCODING='ascii')
|
||||||
|
self.assertIn(file_path.encode('ascii', 'backslashreplace'), stderr)
|
||||||
|
|
||||||
def test_loop(self):
|
def test_loop(self):
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
|
|
|
@ -534,7 +534,7 @@ class CommonTest(GenericTest):
|
||||||
class PathLikeTests(unittest.TestCase):
|
class PathLikeTests(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file_name = support.TESTFN.lower()
|
self.file_name = support.TESTFN
|
||||||
self.file_path = FakePath(support.TESTFN)
|
self.file_path = FakePath(support.TESTFN)
|
||||||
self.addCleanup(support.unlink, self.file_name)
|
self.addCleanup(support.unlink, self.file_name)
|
||||||
create_file(self.file_name, b"test_genericpath.PathLikeTests")
|
create_file(self.file_name, b"test_genericpath.PathLikeTests")
|
||||||
|
|
|
@ -328,8 +328,15 @@ class TestGzip(BaseTest):
|
||||||
cmByte = fRead.read(1)
|
cmByte = fRead.read(1)
|
||||||
self.assertEqual(cmByte, b'\x08') # deflate
|
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)
|
flagsByte = fRead.read(1)
|
||||||
self.assertEqual(flagsByte, b'\x08') # only the FNAME flag is set
|
self.assertEqual(flagsByte, expectedflags)
|
||||||
|
|
||||||
mtimeBytes = fRead.read(4)
|
mtimeBytes = fRead.read(4)
|
||||||
self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
|
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.
|
# 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
|
# However, the gzip module defaults to storing the name of the output
|
||||||
# file in this field.
|
# file in this field.
|
||||||
expected = self.filename.encode('Latin-1') + b'\x00'
|
nameBytes = fRead.read(len(expectedname))
|
||||||
nameBytes = fRead.read(len(expected))
|
self.assertEqual(nameBytes, expectedname)
|
||||||
self.assertEqual(nameBytes, expected)
|
|
||||||
|
|
||||||
# Since no other flags were set, the header ends here.
|
# Since no other flags were set, the header ends here.
|
||||||
# Rather than process the compressed data, let's seek to the trailer.
|
# Rather than process the compressed data, let's seek to the trailer.
|
||||||
|
@ -358,6 +364,10 @@ class TestGzip(BaseTest):
|
||||||
isizeBytes = fRead.read(4)
|
isizeBytes = fRead.read(4)
|
||||||
self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
|
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):
|
def test_compresslevel_metadata(self):
|
||||||
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
|
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
|
||||||
# specifically, discussion of XFL in section 2.3.1
|
# specifically, discussion of XFL in section 2.3.1
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
""" Test suite for the code in msilib """
|
""" Test suite for the code in msilib """
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import TESTFN, FS_NONASCII, import_module, unlink
|
from test.support import TESTFN, import_module, unlink
|
||||||
msilib = import_module('msilib')
|
msilib = import_module('msilib')
|
||||||
import msilib.schema
|
import msilib.schema
|
||||||
|
|
||||||
|
|
||||||
def init_database():
|
def init_database():
|
||||||
path = TESTFN + (FS_NONASCII or '') + '.msi'
|
path = TESTFN + '.msi'
|
||||||
db = msilib.init_database(
|
db = msilib.init_database(
|
||||||
path,
|
path,
|
||||||
msilib.schema,
|
msilib.schema,
|
||||||
|
|
|
@ -725,7 +725,7 @@ class PathLikeTests(NtpathTestCase):
|
||||||
path = ntpath
|
path = ntpath
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file_name = support.TESTFN.lower()
|
self.file_name = support.TESTFN
|
||||||
self.file_path = FakePath(support.TESTFN)
|
self.file_path = FakePath(support.TESTFN)
|
||||||
self.addCleanup(support.unlink, self.file_name)
|
self.addCleanup(support.unlink, self.file_name)
|
||||||
with open(self.file_name, 'xb', 0) as file:
|
with open(self.file_name, 'xb', 0) as file:
|
||||||
|
|
|
@ -1174,7 +1174,7 @@ class WalkTests(unittest.TestCase):
|
||||||
os.makedirs(t2_path)
|
os.makedirs(t2_path)
|
||||||
|
|
||||||
for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path, tmp5_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")
|
f.write("I'm " + path + " and proud of it. Blame test_os.\n")
|
||||||
|
|
||||||
if support.can_symlink():
|
if support.can_symlink():
|
||||||
|
@ -2360,7 +2360,7 @@ class Win32ListdirTests(unittest.TestCase):
|
||||||
file_name = 'FILE%d' % i
|
file_name = 'FILE%d' % i
|
||||||
file_path = os.path.join(support.TESTFN, file_name)
|
file_path = os.path.join(support.TESTFN, file_name)
|
||||||
os.makedirs(dir_path)
|
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)
|
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.extend([dir_name, file_name])
|
||||||
self.created_paths.sort()
|
self.created_paths.sort()
|
||||||
|
@ -3738,7 +3738,7 @@ class PathTConverterTests(unittest.TestCase):
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
bytes_fspath = bytes_filename = None
|
bytes_fspath = bytes_filename = None
|
||||||
else:
|
else:
|
||||||
bytes_filename = support.TESTFN.encode('ascii')
|
bytes_filename = os.fsencode(support.TESTFN)
|
||||||
bytes_fspath = FakePath(bytes_filename)
|
bytes_fspath = FakePath(bytes_filename)
|
||||||
fd = os.open(FakePath(str_filename), os.O_WRONLY|os.O_CREAT)
|
fd = os.open(FakePath(str_filename), os.O_WRONLY|os.O_CREAT)
|
||||||
self.addCleanup(support.unlink, support.TESTFN)
|
self.addCleanup(support.unlink, support.TESTFN)
|
||||||
|
|
|
@ -1198,6 +1198,7 @@ class PdbTestCase(unittest.TestCase):
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
|
env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
|
||||||
) as proc:
|
) as proc:
|
||||||
stdout, stderr = proc.communicate(str.encode(commands))
|
stdout, stderr = proc.communicate(str.encode(commands))
|
||||||
stdout = stdout and bytes.decode(stdout)
|
stdout = stdout and bytes.decode(stdout)
|
||||||
|
@ -1353,10 +1354,11 @@ def bœr():
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
|
env={**os.environ, 'PYTHONIOENCODING': 'utf-8'}
|
||||||
)
|
)
|
||||||
self.addCleanup(proc.stdout.close)
|
self.addCleanup(proc.stdout.close)
|
||||||
stdout, stderr = proc.communicate(b'cont\n')
|
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")
|
"Got an error running test script under PDB")
|
||||||
|
|
||||||
def test_issue36250(self):
|
def test_issue36250(self):
|
||||||
|
@ -1382,10 +1384,11 @@ def bœr():
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
|
env = {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
|
||||||
)
|
)
|
||||||
self.addCleanup(proc.stdout.close)
|
self.addCleanup(proc.stdout.close)
|
||||||
stdout, stderr = proc.communicate(b'cont\ncont\n')
|
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")
|
"Got an error running test script under PDB")
|
||||||
|
|
||||||
def test_issue16180(self):
|
def test_issue16180(self):
|
||||||
|
@ -1425,8 +1428,8 @@ def bœr():
|
||||||
)
|
)
|
||||||
with proc:
|
with proc:
|
||||||
stdout, stderr = proc.communicate(b'q\n')
|
stdout, stderr = proc.communicate(b'q\n')
|
||||||
self.assertNotIn("NameError: name 'invalid' is not defined",
|
self.assertNotIn(b"NameError: name 'invalid' is not defined",
|
||||||
stdout.decode())
|
stdout)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if save_home is not None:
|
if save_home is not None:
|
||||||
|
|
|
@ -627,7 +627,7 @@ class PathLikeTests(unittest.TestCase):
|
||||||
path = posixpath
|
path = posixpath
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file_name = support.TESTFN.lower()
|
self.file_name = support.TESTFN
|
||||||
self.file_path = FakePath(support.TESTFN)
|
self.file_path = FakePath(support.TESTFN)
|
||||||
self.addCleanup(support.unlink, self.file_name)
|
self.addCleanup(support.unlink, self.file_name)
|
||||||
with open(self.file_name, 'xb', 0) as file:
|
with open(self.file_name, 'xb', 0) as file:
|
||||||
|
|
|
@ -2305,7 +2305,8 @@ class CommandLineTest(unittest.TestCase):
|
||||||
def test_test_command_verbose(self):
|
def test_test_command_verbose(self):
|
||||||
for tar_name in testtarnames:
|
for tar_name in testtarnames:
|
||||||
for opt in '-v', '--verbose':
|
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)
|
self.assertIn(b'is a tar archive.\n', out)
|
||||||
|
|
||||||
def test_test_command_invalid_file(self):
|
def test_test_command_invalid_file(self):
|
||||||
|
@ -2376,7 +2377,8 @@ class CommandLineTest(unittest.TestCase):
|
||||||
'and-utf8-bom-sig-only.txt')]
|
'and-utf8-bom-sig-only.txt')]
|
||||||
for opt in '-v', '--verbose':
|
for opt in '-v', '--verbose':
|
||||||
try:
|
try:
|
||||||
out = self.tarfilecmd(opt, '-c', tmpname, *files)
|
out = self.tarfilecmd(opt, '-c', tmpname, *files,
|
||||||
|
PYTHONIOENCODING='utf-8')
|
||||||
self.assertIn(b' file created.', out)
|
self.assertIn(b' file created.', out)
|
||||||
with tarfile.open(tmpname) as tar:
|
with tarfile.open(tmpname) as tar:
|
||||||
tar.getmembers()
|
tar.getmembers()
|
||||||
|
@ -2434,7 +2436,8 @@ class CommandLineTest(unittest.TestCase):
|
||||||
for opt in '-v', '--verbose':
|
for opt in '-v', '--verbose':
|
||||||
try:
|
try:
|
||||||
with support.temp_cwd(tarextdir):
|
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)
|
self.assertIn(b' file is extracted.', out)
|
||||||
finally:
|
finally:
|
||||||
support.rmtree(tarextdir)
|
support.rmtree(tarextdir)
|
||||||
|
|
|
@ -30,16 +30,18 @@ class TestPathfixFunctional(unittest.TestCase):
|
||||||
with open(filename, 'w', encoding='utf8') as f:
|
with open(filename, 'w', encoding='utf8') as f:
|
||||||
f.write(f'{shebang}\n' + 'print("Hello world")\n')
|
f.write(f'{shebang}\n' + 'print("Hello world")\n')
|
||||||
|
|
||||||
|
encoding = sys.getfilesystemencoding()
|
||||||
proc = subprocess.run(
|
proc = subprocess.run(
|
||||||
[sys.executable, self.script,
|
[sys.executable, self.script,
|
||||||
*pathfix_flags, '-n', pathfix_arg],
|
*pathfix_flags, '-n', pathfix_arg],
|
||||||
capture_output=True, text=1)
|
env={**os.environ, 'PYTHONIOENCODING': encoding},
|
||||||
|
capture_output=True)
|
||||||
|
|
||||||
if stdout == '' and proc.returncode == 0:
|
if stdout == '' and proc.returncode == 0:
|
||||||
stdout = f'{filename}: updating\n'
|
stdout = f'{filename}: updating\n'
|
||||||
self.assertEqual(proc.returncode, exitcode, proc)
|
self.assertEqual(proc.returncode, exitcode, proc)
|
||||||
self.assertEqual(proc.stdout, stdout, proc)
|
self.assertEqual(proc.stdout.decode(encoding), stdout.replace('\n', os.linesep), proc)
|
||||||
self.assertEqual(proc.stderr, stderr, proc)
|
self.assertEqual(proc.stderr.decode(encoding), stderr.replace('\n', os.linesep), proc)
|
||||||
|
|
||||||
with open(filename, 'r', encoding='utf8') as f:
|
with open(filename, 'r', encoding='utf8') as f:
|
||||||
output = f.read()
|
output = f.read()
|
||||||
|
|
|
@ -488,7 +488,8 @@ class TestCommandLine(unittest.TestCase):
|
||||||
with open(TESTFN, 'w') as fd:
|
with open(TESTFN, 'w') as fd:
|
||||||
self.addCleanup(unlink, TESTFN)
|
self.addCleanup(unlink, TESTFN)
|
||||||
fd.write("a = 1\n")
|
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)
|
self.assertIn(b'functions called:', stdout)
|
||||||
|
|
||||||
def test_sys_argv_list(self):
|
def test_sys_argv_list(self):
|
||||||
|
@ -498,7 +499,8 @@ class TestCommandLine(unittest.TestCase):
|
||||||
fd.write("print(type(sys.argv))\n")
|
fd.write("print(type(sys.argv))\n")
|
||||||
|
|
||||||
status, direct_stdout, stderr = assert_python_ok(TESTFN)
|
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)
|
self.assertIn(direct_stdout.strip(), trace_stdout)
|
||||||
|
|
||||||
def test_count_and_summary(self):
|
def test_count_and_summary(self):
|
||||||
|
@ -517,7 +519,8 @@ class TestCommandLine(unittest.TestCase):
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
f()
|
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()
|
stdout = stdout.decode()
|
||||||
self.assertEqual(status, 0)
|
self.assertEqual(status, 0)
|
||||||
self.assertIn('lines cov% module (path)', stdout)
|
self.assertIn('lines cov% module (path)', stdout)
|
||||||
|
|
|
@ -151,7 +151,8 @@ class urlopen_FileTests(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
self.pathname = support.TESTFN
|
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):
|
def tearDown(self):
|
||||||
"""Shut down the open object"""
|
"""Shut down the open object"""
|
||||||
|
@ -198,7 +199,7 @@ class urlopen_FileTests(unittest.TestCase):
|
||||||
self.assertIsInstance(self.returned_obj.headers, email.message.Message)
|
self.assertIsInstance(self.returned_obj.headers, email.message.Message)
|
||||||
|
|
||||||
def test_url(self):
|
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):
|
def test_status(self):
|
||||||
self.assertIsNone(self.returned_obj.status)
|
self.assertIsNone(self.returned_obj.status)
|
||||||
|
@ -207,7 +208,7 @@ class urlopen_FileTests(unittest.TestCase):
|
||||||
self.assertIsInstance(self.returned_obj.info(), email.message.Message)
|
self.assertIsInstance(self.returned_obj.info(), email.message.Message)
|
||||||
|
|
||||||
def test_geturl(self):
|
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):
|
def test_getcode(self):
|
||||||
self.assertIsNone(self.returned_obj.getcode())
|
self.assertIsNone(self.returned_obj.getcode())
|
||||||
|
|
|
@ -174,8 +174,9 @@ class UUStdIOTest(unittest.TestCase):
|
||||||
class UUFileTest(unittest.TestCase):
|
class UUFileTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.tmpin = os_helper.TESTFN + "i"
|
# uu.encode() supports only ASCII file names
|
||||||
self.tmpout = os_helper.TESTFN + "o"
|
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.tmpin)
|
||||||
self.addCleanup(os_helper.unlink, self.tmpout)
|
self.addCleanup(os_helper.unlink, self.tmpout)
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ class BaseTest(unittest.TestCase):
|
||||||
def get_env_file(self, *args):
|
def get_env_file(self, *args):
|
||||||
return os.path.join(self.env_dir, *args)
|
return os.path.join(self.env_dir, *args)
|
||||||
|
|
||||||
def get_text_file_contents(self, *args):
|
def get_text_file_contents(self, *args, encoding='utf-8'):
|
||||||
with open(self.get_env_file(*args), 'r') as f:
|
with open(self.get_env_file(*args), 'r', encoding=encoding) as f:
|
||||||
result = f.read()
|
result = f.read()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -940,8 +940,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
def run(*args):
|
def run(*args):
|
||||||
res = assert_python_ok(*args)
|
res = assert_python_ok(*args, PYTHONIOENCODING='utf-8')
|
||||||
stderr = res.err.decode('ascii', 'replace')
|
stderr = res.err.decode('utf-8', 'replace')
|
||||||
stderr = '\n'.join(stderr.splitlines())
|
stderr = '\n'.join(stderr.splitlines())
|
||||||
|
|
||||||
# normalize newlines
|
# normalize newlines
|
||||||
|
@ -1198,7 +1198,7 @@ class EnvironmentVariableTests(BaseTest):
|
||||||
@unittest.skipUnless(sys.getfilesystemencoding() != 'ascii',
|
@unittest.skipUnless(sys.getfilesystemencoding() != 'ascii',
|
||||||
'requires non-ascii filesystemencoding')
|
'requires non-ascii filesystemencoding')
|
||||||
def test_nonascii(self):
|
def test_nonascii(self):
|
||||||
PYTHONWARNINGS="ignore:DeprecationWarning" + (support.FS_NONASCII or '')
|
PYTHONWARNINGS="ignore:DeprecationWarning" + support.FS_NONASCII
|
||||||
rc, stdout, stderr = assert_python_ok("-c",
|
rc, stdout, stderr = assert_python_ok("-c",
|
||||||
"import sys; sys.stdout.write(str(sys.warnoptions))",
|
"import sys; sys.stdout.write(str(sys.warnoptions))",
|
||||||
PYTHONIOENCODING="utf-8",
|
PYTHONIOENCODING="utf-8",
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:data:`test.support.TESTFN` and the current directory for tests when run via
|
||||||
|
``test.regrtest`` contain now non-ascii characters if possible.
|
|
@ -4235,15 +4235,15 @@ static PyObject*
|
||||||
pymarshal_write_long_to_file(PyObject* self, PyObject *args)
|
pymarshal_write_long_to_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
long value;
|
long value;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
int version;
|
int version;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "lsi:pymarshal_write_long_to_file",
|
if (!PyArg_ParseTuple(args, "lOi:pymarshal_write_long_to_file",
|
||||||
&value, &filename, &version))
|
&value, &filename, &version))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "wb");
|
fp = _Py_fopen_obj(filename, "wb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4261,15 +4261,15 @@ static PyObject*
|
||||||
pymarshal_write_object_to_file(PyObject* self, PyObject *args)
|
pymarshal_write_object_to_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
int version;
|
int version;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Osi:pymarshal_write_object_to_file",
|
if (!PyArg_ParseTuple(args, "OOi:pymarshal_write_object_to_file",
|
||||||
&obj, &filename, &version))
|
&obj, &filename, &version))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "wb");
|
fp = _Py_fopen_obj(filename, "wb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4288,13 +4288,13 @@ pymarshal_read_short_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
long pos;
|
long pos;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s:pymarshal_read_short_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_short_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4313,13 +4313,13 @@ static PyObject*
|
||||||
pymarshal_read_long_from_file(PyObject* self, PyObject *args)
|
pymarshal_read_long_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
long value, pos;
|
long value, pos;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s:pymarshal_read_long_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_long_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4339,13 +4339,13 @@ pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
long pos;
|
long pos;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s:pymarshal_read_last_object_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -4363,13 +4363,13 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
long pos;
|
long pos;
|
||||||
char *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s:pymarshal_read_object_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = fopen(filename, "rb");
|
fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue