mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Issue #9819: don't try to encode TESTFN_UNICODE on Windows
mbcs (Windows default filesystem encoding) is now strict by default, and depending on the code page, TESTFN_UNICODE may not be encodable to bytes. Remove also unused "encoded" argument from _do_directory() method.
This commit is contained in:
parent
4039aff814
commit
ca6525afba
1 changed files with 12 additions and 16 deletions
|
@ -8,9 +8,10 @@ import unittest
|
||||||
from test.support import (run_unittest, rmtree,
|
from test.support import (run_unittest, rmtree,
|
||||||
TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE)
|
TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE)
|
||||||
|
|
||||||
try:
|
if not os.path.supports_unicode_filenames:
|
||||||
|
try:
|
||||||
TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
||||||
except (UnicodeError, TypeError):
|
except (UnicodeError, TypeError):
|
||||||
# Either the file system encoding is None, or the file name
|
# Either the file system encoding is None, or the file name
|
||||||
# cannot be encoded in the file system encoding.
|
# cannot be encoded in the file system encoding.
|
||||||
raise unittest.SkipTest("No Unicode filesystem semantics on this platform.")
|
raise unittest.SkipTest("No Unicode filesystem semantics on this platform.")
|
||||||
|
@ -90,7 +91,7 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
shutil.copy2(filename1, filename2 + ".new")
|
shutil.copy2(filename1, filename2 + ".new")
|
||||||
os.unlink(filename1 + ".new")
|
os.unlink(filename1 + ".new")
|
||||||
|
|
||||||
def _do_directory(self, make_name, chdir_name, encoded):
|
def _do_directory(self, make_name, chdir_name):
|
||||||
cwd = os.getcwdb()
|
cwd = os.getcwdb()
|
||||||
if os.path.isdir(make_name):
|
if os.path.isdir(make_name):
|
||||||
rmtree(make_name)
|
rmtree(make_name)
|
||||||
|
@ -98,12 +99,8 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
os.chdir(chdir_name)
|
os.chdir(chdir_name)
|
||||||
try:
|
try:
|
||||||
if not encoded:
|
|
||||||
cwd_result = os.getcwd()
|
cwd_result = os.getcwd()
|
||||||
name_result = make_name
|
name_result = make_name
|
||||||
else:
|
|
||||||
cwd_result = os.getcwdb().decode(TESTFN_ENCODING)
|
|
||||||
name_result = make_name.decode(TESTFN_ENCODING)
|
|
||||||
|
|
||||||
cwd_result = unicodedata.normalize("NFD", cwd_result)
|
cwd_result = unicodedata.normalize("NFD", cwd_result)
|
||||||
name_result = unicodedata.normalize("NFD", name_result)
|
name_result = unicodedata.normalize("NFD", name_result)
|
||||||
|
@ -155,12 +152,11 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
# Make dir with encoded, chdir with unicode, checkdir with encoded
|
# Make dir with encoded, chdir with unicode, checkdir with encoded
|
||||||
# (or unicode/encoded/unicode, etc
|
# (or unicode/encoded/unicode, etc
|
||||||
ext = ".dir"
|
ext = ".dir"
|
||||||
self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, False)
|
self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext)
|
||||||
# Our directory name that can't use a non-unicode name.
|
# Our directory name that can't use a non-unicode name.
|
||||||
if TESTFN_UNENCODABLE is not None:
|
if TESTFN_UNENCODABLE is not None:
|
||||||
self._do_directory(TESTFN_UNENCODABLE+ext,
|
self._do_directory(TESTFN_UNENCODABLE+ext,
|
||||||
TESTFN_UNENCODABLE+ext,
|
TESTFN_UNENCODABLE+ext)
|
||||||
False)
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
run_unittest(__name__)
|
run_unittest(__name__)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue