Skip to content

bpo-40275: remove TESTFN_ENCODING in test.support #20482

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 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ The :mod:`test.support` module defines the following constants:
Set to a non-ASCII name for a temporary file.


.. data:: TESTFN_ENCODING

Set to :func:`sys.getfilesystemencoding`.


.. data:: TESTFN_UNENCODABLE

Set to a filename (str type) that should not be able to be encoded by file
Expand Down
11 changes: 5 additions & 6 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ def requires_lzma(reason='requires lzma'):
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
import unicodedata
TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE)
TESTFN_ENCODING = sys.getfilesystemencoding()

# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be
# encoded by the filesystem encoding (in strict mode). It can be None if we
Expand All @@ -798,23 +797,23 @@ def requires_lzma(reason='requires lzma'):
# probability that the whole name is encodable to MBCS (issue #9819)
TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80"
try:
TESTFN_UNENCODABLE.encode(TESTFN_ENCODING)
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
pass
else:
print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
'Unicode filename tests may not be effective'
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
% (TESTFN_UNENCODABLE, sys.getfilesystemencoding()))
TESTFN_UNENCODABLE = None
# Mac OS X denies unencodable filenames (invalid utf-8)
elif sys.platform != 'darwin':
try:
# ascii and utf-8 cannot encode the byte 0xff
b'\xff'.decode(TESTFN_ENCODING)
b'\xff'.decode(sys.getfilesystemencoding())
except UnicodeDecodeError:
# 0xff will be encoded using the surrogate character u+DCFF
TESTFN_UNENCODABLE = TESTFN \
+ b'-\xff'.decode(TESTFN_ENCODING, 'surrogateescape')
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
else:
# File system encoding (eg. ISO-8859-* encodings) can encode
# the byte 0xff. Skip some unicode filename tests.
Expand Down Expand Up @@ -845,7 +844,7 @@ def requires_lzma(reason='requires lzma'):
b'\x81\x98',
):
try:
name.decode(TESTFN_ENCODING)
name.decode(sys.getfilesystemencoding())
except UnicodeDecodeError:
TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
break
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_sax.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import codecs
import os.path
import shutil
import sys
from urllib.error import URLError
import urllib.request
from test import support
Expand All @@ -35,7 +36,7 @@
supports_nonascii_filenames = True
if not os.path.supports_unicode_filenames:
try:
support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING)
support.TESTFN_UNICODE.encode(sys.getfilesystemencoding())
except (UnicodeError, TypeError):
# Either the file system encoding is None, or the file name
# cannot be encoded in the file system encoding.
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_unicode_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# We don't test many operations on files other than
# that their names can be used with Unicode characters.
import os, glob, time, shutil
import sys
import unicodedata

import unittest
from test.support import (run_unittest, rmtree, change_cwd,
TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)
TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)

if not os.path.supports_unicode_filenames:
try:
TESTFN_UNICODE.encode(TESTFN_ENCODING)
TESTFN_UNICODE.encode(sys.getfilesystemencoding())
except (UnicodeError, TypeError):
# Either the file system encoding is None, or the file name
# cannot be encoded in the file system encoding.
Expand Down