diff -r 57649a9a683c Lib/test/support.py --- a/Lib/test/support.py Wed Nov 07 23:20:10 2012 +0100 +++ b/Lib/test/support.py Thu Nov 08 23:48:31 2012 +0100 @@ -692,7 +692,10 @@ elif sys.platform != 'darwin': # TESTFN_UNDECODABLE is a filename (bytes type) that should *not* be able to be # decoded from the filesystem encoding (in strict mode). It can be None if we -# cannot generate such filename. +# cannot generate such filename (ex: the latin1 encoding can decode any byte +# sequence). On UNIX, TESTFN_UNDECODABLE can be decoded by os.fsdecode() thanks +# to the surrogateescape error handler (PEP 383), but not from the filesystem +# encoding in strict mode. TESTFN_UNDECODABLE = None # 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 @@ -700,7 +703,7 @@ TESTFN_UNDECODABLE = None # not decodable from cp932. for name in (b'\xe7w\xf0', b'abc\xff'): try: - os.fsdecode(name) + name.decode(TESTFN_ENCODING) except UnicodeDecodeError: TESTFN_UNDECODABLE = name break @@ -710,6 +713,9 @@ if FS_NONASCII: else: TESTFN_NONASCII = None +print("TESTFN_UNDECODABLE = %a" % TESTFN_UNDECODABLE) +print("TESTFN_NONASCII = %a" % TESTFN_NONASCII) + # Save the initial cwd SAVEDCWD = os.getcwd() diff -r 57649a9a683c Lib/test/test_cmd_line_script.py --- a/Lib/test/test_cmd_line_script.py Wed Nov 07 23:20:10 2012 +0100 +++ b/Lib/test/test_cmd_line_script.py Thu Nov 08 23:48:31 2012 +0100 @@ -363,11 +363,22 @@ class CmdLineTest(unittest.TestCase): self.assertTrue(text[1].startswith(' File ')) self.assertTrue(text[3].startswith('NameError')) - @unittest.skipUnless(support.TESTFN_NONASCII, 'need support.TESTFN_NONASCII') def test_non_ascii(self): + if (support.TESTFN_UNDECODABLE + # 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). + and sys.platform not in ('win32', 'darwin')): + name = os.fsdecode(support.TESTFN_UNDECODABLE) + elif support.TESTFN_NONASCII: + name = support.TESTFN_NONASCII + else: + self.skipTest("need support.TESTFN_NONASCII") + # Issue #16218 source = 'print(ascii(__file__))\n' - script_name = _make_test_script(os.curdir, support.TESTFN_NONASCII, source) + script_name = _make_test_script(os.curdir, name, source) self.addCleanup(support.unlink, script_name) rc, stdout, stderr = assert_python_ok(script_name) self.assertEqual( diff -r 57649a9a683c Lib/test/test_genericpath.py --- a/Lib/test/test_genericpath.py Wed Nov 07 23:20:10 2012 +0100 +++ b/Lib/test/test_genericpath.py Thu Nov 08 23:48:31 2012 +0100 @@ -309,26 +309,17 @@ class CommonTest(GenericTest): self.assertIsInstance(abspath(path), str) def test_nonascii_abspath(self): - # 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") + if (support.TESTFN_UNDECODABLE + # 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). + and sys.platform not in ('win32', 'darwin')): + name = support.TESTFN_UNDECODABLE + elif support.TESTFN_NONASCII: + name = support.TESTFN_NONASCII else: - 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' + self.skipTest("need support.TESTFN_NONASCII") with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning)