Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 706e0b4

Browse files
author
Victor Stinner
committed
Backport test_getfilesystemencoding() from py3k
Note: On Python 3.1, file system encoding can be None.
1 parent d5054cf commit 706e0b4

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lib/test/test_sys.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,36 @@ def test_pythontypes(self):
792792
# sys.flags
793793
check(sys.flags, size(vh) + self.P * len(sys.flags))
794794

795+
def test_getfilesystemencoding(self):
796+
import codecs
797+
798+
def check_fsencoding(fs_encoding):
799+
if sys.platform == 'darwin':
800+
self.assertEqual(fs_encoding, 'utf-8')
801+
elif fs_encoding is None:
802+
return
803+
codecs.lookup(fs_encoding)
804+
805+
fs_encoding = sys.getfilesystemencoding()
806+
check_fsencoding(fs_encoding)
807+
808+
# Even in C locale
809+
try:
810+
sys.executable.encode('ascii')
811+
except UnicodeEncodeError:
812+
# Python doesn't start with ASCII locale if its path is not ASCII,
813+
# see issue #8611
814+
pass
815+
else:
816+
env = os.environ.copy()
817+
env['LANG'] = 'C'
818+
output = subprocess.check_output(
819+
[sys.executable, "-c",
820+
"import sys; print(sys.getfilesystemencoding())"],
821+
env=env)
822+
fs_encoding = output.rstrip().decode('ascii')
823+
check_fsencoding(fs_encoding)
824+
795825
def test_setfilesystemencoding(self):
796826
old = sys.getfilesystemencoding()
797827
try:

0 commit comments

Comments
 (0)