From 750291e65133cdff704b5bdba4b7d33e7883b20b Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Thu, 31 May 2018 11:34:35 +0300 Subject: [PATCH 1/2] test_ntpath and test_posixpath failed if sys.getfilesystemencoding()=='mbcs' --- Lib/test/support/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index a6fcb1bc143784..988344ac35e8e4 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -844,7 +844,8 @@ def dec(*args, **kwargs): '\u20AC', ): try: - os.fsdecode(os.fsencode(character)) + if os.fsdecode(os.fsencode(character)) != character: + raise UnicodeError except UnicodeError: pass else: From 9c9db384c65c950e725e45c0fd0500b6443855cc Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Fri, 1 Jun 2018 01:10:51 +0300 Subject: [PATCH 2/2] comment the new logic --- Lib/test/support/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 988344ac35e8e4..c6cf8c6f9b2b1a 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -844,6 +844,9 @@ def dec(*args, **kwargs): '\u20AC', ): try: + # If Python is set up to use the legacy 'mbcs' in Windows, + # 'replace' error mode is used, and encode() returns b'?' + # for characters missing in the ANSI codepage if os.fsdecode(os.fsencode(character)) != character: raise UnicodeError except UnicodeError: