Commit 9a45a6b1 authored by Victor Stinner's avatar Victor Stinner

Issue #8965: Write more tests for sys.getfilesystemencoding()

parent 19e65a35
......@@ -863,21 +863,34 @@ class SizeofTest(unittest.TestCase):
# sys.flags
check(sys.flags, size(vh) + self.P * len(sys.flags))
@unittest.skipUnless(sys.platform == 'darwin', "test specific to Mac OS X")
def test_getfilesystemencoding(self):
# On Darwing FS encoding is always UTF-8
fs_encoding = sys.getfilesystemencoding()
import codecs
def check_fsencoding(fs_encoding):
self.assertIsNotNone(fs_encoding)
if sys.platform == 'darwin':
self.assertEqual(fs_encoding, 'utf-8')
codecs.lookup(fs_encoding)
fs_encoding = sys.getfilesystemencoding()
check_fsencoding(fs_encoding)
# Even in C locale
try:
sys.executable.encode('ascii')
except UnicodeEncodeError:
# Python doesn't start with ASCII locale if its path is not ASCII,
# see issue #8611
pass
else:
env = os.environ.copy()
env['LANG'] = 'C'
output = subprocess.check_output(
[sys.executable, "-c",
"import sys; print(sys.getfilesystemencoding())"],
env=env)
fs_encoding = output.rstrip()
self.assertEqual(fs_encoding, b'utf-8')
fs_encoding = output.rstrip().decode('ascii')
check_fsencoding(fs_encoding)
def test_setfilesystemencoding(self):
old = sys.getfilesystemencoding()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment