mirror of
https://github.com/python/cpython.git
synced 2025-10-11 17:32:49 +00:00
Normalized files in test_unicode_file to eliminate failure on OSX
This commit is contained in:
parent
56716150e6
commit
668034173b
1 changed files with 29 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
# We dont test many operations on files other than
|
# We dont test many operations on files other than
|
||||||
# that their names can be used with Unicode characters.
|
# that their names can be used with Unicode characters.
|
||||||
import os, glob, time, shutil
|
import os, glob, time, shutil
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.test_support import run_suite, TestSkipped, TESTFN_UNICODE
|
from test.test_support import run_suite, TestSkipped, TESTFN_UNICODE
|
||||||
|
@ -38,7 +39,17 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
os.path.abspath(filename)==os.path.abspath(glob.glob(filename)[0]))
|
os.path.abspath(filename)==os.path.abspath(glob.glob(filename)[0]))
|
||||||
# basename should appear in listdir.
|
# basename should appear in listdir.
|
||||||
path, base = os.path.split(os.path.abspath(filename))
|
path, base = os.path.split(os.path.abspath(filename))
|
||||||
self.failUnless(base in os.listdir(path))
|
if (isinstance (filename, str)):
|
||||||
|
new_base = base.decode(TESTFN_ENCODING)
|
||||||
|
file_list = [f.decode(TESTFN_ENCODING) for f in os.listdir(path)]
|
||||||
|
else:
|
||||||
|
new_base = base
|
||||||
|
file_list = os.listdir(path)
|
||||||
|
|
||||||
|
new_base = unicodedata.normalize("NFD", new_base)
|
||||||
|
file_list = [unicodedata.normalize("NFD", f) for f in file_list]
|
||||||
|
|
||||||
|
self.failUnless(new_base in file_list)
|
||||||
|
|
||||||
# Do as many "equivalancy' tests as we can - ie, check that although we
|
# Do as many "equivalancy' tests as we can - ie, check that although we
|
||||||
# have different types for the filename, they refer to the same file.
|
# have different types for the filename, they refer to the same file.
|
||||||
|
@ -91,7 +102,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, getcwd_func):
|
def _do_directory(self, make_name, chdir_name, encoded):
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
if os.path.isdir(make_name):
|
if os.path.isdir(make_name):
|
||||||
os.rmdir(make_name)
|
os.rmdir(make_name)
|
||||||
|
@ -99,8 +110,17 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
os.chdir(chdir_name)
|
os.chdir(chdir_name)
|
||||||
try:
|
try:
|
||||||
self.failUnlessEqual(os.path.basename(getcwd_func()),
|
if not encoded:
|
||||||
make_name)
|
cwd_result = os.getcwdu()
|
||||||
|
name_result = make_name
|
||||||
|
else:
|
||||||
|
cwd_result = os.getcwd().decode(TESTFN_ENCODING)
|
||||||
|
name_result = make_name.decode(TESTFN_ENCODING)
|
||||||
|
|
||||||
|
cwd_result = unicodedata.normalize("NFD", cwd_result)
|
||||||
|
name_result = unicodedata.normalize("NFD", name_result)
|
||||||
|
|
||||||
|
self.failUnlessEqual(os.path.basename(cwd_result),name_result)
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
finally:
|
finally:
|
||||||
|
@ -152,15 +172,15 @@ 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_ENCODED+ext, TESTFN_ENCODED+ext, os.getcwd)
|
self._do_directory(TESTFN_ENCODED+ext, TESTFN_ENCODED+ext, True)
|
||||||
self._do_directory(TESTFN_ENCODED+ext, TESTFN_UNICODE+ext, os.getcwd)
|
self._do_directory(TESTFN_ENCODED+ext, TESTFN_UNICODE+ext, True)
|
||||||
self._do_directory(TESTFN_UNICODE+ext, TESTFN_ENCODED+ext, os.getcwdu)
|
self._do_directory(TESTFN_UNICODE+ext, TESTFN_ENCODED+ext, False)
|
||||||
self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, os.getcwdu)
|
self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, False)
|
||||||
# Our directory name that can't use a non-unicode name.
|
# Our directory name that can't use a non-unicode name.
|
||||||
if TESTFN_UNICODE_UNENCODEABLE is not None:
|
if TESTFN_UNICODE_UNENCODEABLE is not None:
|
||||||
self._do_directory(TESTFN_UNICODE_UNENCODEABLE+ext,
|
self._do_directory(TESTFN_UNICODE_UNENCODEABLE+ext,
|
||||||
TESTFN_UNICODE_UNENCODEABLE+ext,
|
TESTFN_UNICODE_UNENCODEABLE+ext,
|
||||||
os.getcwdu)
|
False)
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue