Skip to content

Commit 24bddc1

Browse files
authored
bpo-40275: Remove test.support.TESTFN_ENCODING (GH-20482)
Replace test.support.TESTFN_ENCODING with sys.getfilesystemencoding().
1 parent 84ee7e1 commit 24bddc1

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

Doc/library/test.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ The :mod:`test.support` module defines the following constants:
263263
Set to a non-ASCII name for a temporary file.
264264

265265

266-
.. data:: TESTFN_ENCODING
267-
268-
Set to :func:`sys.getfilesystemencoding`.
269-
270-
271266
.. data:: TESTFN_UNENCODABLE
272267

273268
Set to a filename (str type) that should not be able to be encoded by file

Lib/test/support/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ def requires_lzma(reason='requires lzma'):
785785
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
786786
import unicodedata
787787
TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE)
788-
TESTFN_ENCODING = sys.getfilesystemencoding()
789788

790789
# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be
791790
# encoded by the filesystem encoding (in strict mode). It can be None if we
@@ -798,23 +797,23 @@ def requires_lzma(reason='requires lzma'):
798797
# probability that the whole name is encodable to MBCS (issue #9819)
799798
TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80"
800799
try:
801-
TESTFN_UNENCODABLE.encode(TESTFN_ENCODING)
800+
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
802801
except UnicodeEncodeError:
803802
pass
804803
else:
805804
print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
806805
'Unicode filename tests may not be effective'
807-
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
806+
% (TESTFN_UNENCODABLE, sys.getfilesystemencoding()))
808807
TESTFN_UNENCODABLE = None
809808
# Mac OS X denies unencodable filenames (invalid utf-8)
810809
elif sys.platform != 'darwin':
811810
try:
812811
# ascii and utf-8 cannot encode the byte 0xff
813-
b'\xff'.decode(TESTFN_ENCODING)
812+
b'\xff'.decode(sys.getfilesystemencoding())
814813
except UnicodeDecodeError:
815814
# 0xff will be encoded using the surrogate character u+DCFF
816815
TESTFN_UNENCODABLE = TESTFN \
817-
+ b'-\xff'.decode(TESTFN_ENCODING, 'surrogateescape')
816+
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
818817
else:
819818
# File system encoding (eg. ISO-8859-* encodings) can encode
820819
# the byte 0xff. Skip some unicode filename tests.
@@ -845,7 +844,7 @@ def requires_lzma(reason='requires lzma'):
845844
b'\x81\x98',
846845
):
847846
try:
848-
name.decode(TESTFN_ENCODING)
847+
name.decode(sys.getfilesystemencoding())
849848
except UnicodeDecodeError:
850849
TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
851850
break

Lib/test/test_sax.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import codecs
2020
import os.path
2121
import shutil
22+
import sys
2223
from urllib.error import URLError
2324
import urllib.request
2425
from test import support
@@ -35,7 +36,7 @@
3536
supports_nonascii_filenames = True
3637
if not os.path.supports_unicode_filenames:
3738
try:
38-
support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING)
39+
support.TESTFN_UNICODE.encode(sys.getfilesystemencoding())
3940
except (UnicodeError, TypeError):
4041
# Either the file system encoding is None, or the file name
4142
# cannot be encoded in the file system encoding.

Lib/test/test_unicode_file.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# We don't test many operations on files other than
33
# that their names can be used with Unicode characters.
44
import os, glob, time, shutil
5+
import sys
56
import unicodedata
67

78
import unittest
89
from test.support import (run_unittest, rmtree, change_cwd,
9-
TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)
10+
TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)
1011

1112
if not os.path.supports_unicode_filenames:
1213
try:
13-
TESTFN_UNICODE.encode(TESTFN_ENCODING)
14+
TESTFN_UNICODE.encode(sys.getfilesystemencoding())
1415
except (UnicodeError, TypeError):
1516
# Either the file system encoding is None, or the file name
1617
# cannot be encoded in the file system encoding.

0 commit comments

Comments
 (0)