diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-06-25 14:56:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 14:56:31 (GMT) |
commit | 700cfa8c90a90016638bac13c4efd03786b2b2a0 (patch) | |
tree | 62994f7b8d6fccd910d5f65bd6cd49a4f72bf8ae /Lib/test/support | |
parent | 8ea6353f60625c96ce96588c70ff24a77f8c71f9 (diff) | |
download | cpython-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/support')
-rw-r--r-- | Lib/test/support/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/support/os_helper.py | 21 |
2 files changed, 12 insertions, 11 deletions
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(): |