From 8f049e5b5b360900a5f4d429040c8bfdc89d2fc6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 6 Nov 2012 23:33:46 +0100 Subject: Issue #16414: Fix support.TESTFN_UNDECODABLE and test_genericpath.test_nonascii_abspath() * support.TESTFN_UNDECODABLE was decodable if the filesystem encoding was cp932 * test_genericpath.test_nonascii_abspath() didn't work on Windows if the path was not decodable (ex: with cp932) --- Lib/test/support.py | 6 +++++- Lib/test/test_genericpath.py | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Lib/test/support.py b/Lib/test/support.py index 4e946ab..801ecf2 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -677,7 +677,11 @@ elif sys.platform != 'darwin': # decoded from the filesystem encoding (in strict mode). It can be None if we # cannot generate such filename. TESTFN_UNDECODABLE = None -for name in (b'abc\xff', b'\xe7w\xf0'): +# b'\xff' is not decodable by os.fsdecode() with code page 932. Windows +# accepts it to create a file or a directory, or don't accept to enter to +# such directory (when the bytes name is used). So test b'\xe7' first: it is +# not decodable from cp932. +for name in (b'\xe7w\xf0', b'abc\xff'): try: os.fsdecode(name) except UnicodeDecodeError: diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index b1ee110..9d1d2bc 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -308,17 +308,28 @@ class CommonTest(GenericTest): for path in ('', 'fuu', 'f\xf9\xf9', '/fuu', 'U:\\'): self.assertIsInstance(abspath(path), str) - @unittest.skipIf(sys.platform == 'darwin', - "Mac OS X denies the creation of a directory with an invalid utf8 name") def test_nonascii_abspath(self): - if support.TESTFN_UNDECODABLE: - name = support.TESTFN_UNDECODABLE - elif support.TESTFN_NONASCII: - name = support.TESTFN_NONASCII + # Test non-ASCII in the path + if sys.platform in ('win32', 'darwin'): + if support.TESTFN_NONASCII: + name = support.TESTFN_NONASCII + else: + # Mac OS X denies the creation of a directory with an invalid + # UTF-8 name. Windows allows to create a directory with an + # arbitrary bytes name, but fails to enter this directory + # (when the bytes name is used). + self.skipTest("need support.TESTFN_NONASCII") else: - name = b'a\xffb\xe7w\xf0' + if support.TESTFN_UNDECODABLE: + name = support.TESTFN_UNDECODABLE + elif support.TESTFN_NONASCII: + name = support.TESTFN_NONASCII + else: + # On UNIX, the surrogateescape error handler is used to + # decode paths, so any byte is allowed, it does not depend + # on the locale + name = b'a\xffb\xe7w\xf0' - # Test non-ASCII, non-UTF8 bytes in the path. with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) with support.temp_cwd(name): -- cgit v0.12