summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-06-11 23:12:58 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-06-11 23:12:58 (GMT)
commit706e0b43e311cb2e4f605ff1da176af1d574221f (patch)
tree1555b2d84155ef0dbbf0c17284639a089a0a0787
parentd5054cf7ffd84ed0aa2624cd273ad97900e7e488 (diff)
downloadcpython-706e0b43e311cb2e4f605ff1da176af1d574221f.zip
cpython-706e0b43e311cb2e4f605ff1da176af1d574221f.tar.gz
cpython-706e0b43e311cb2e4f605ff1da176af1d574221f.tar.bz2
Backport test_getfilesystemencoding() from py3k
Note: On Python 3.1, file system encoding can be None.
-rw-r--r--Lib/test/test_sys.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 4beb429..24f17fb 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -792,6 +792,36 @@ class SizeofTest(unittest.TestCase):
# sys.flags
check(sys.flags, size(vh) + self.P * len(sys.flags))
+ def test_getfilesystemencoding(self):
+ import codecs
+
+ def check_fsencoding(fs_encoding):
+ if sys.platform == 'darwin':
+ self.assertEqual(fs_encoding, 'utf-8')
+ elif fs_encoding is None:
+ return
+ 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().decode('ascii')
+ check_fsencoding(fs_encoding)
+
def test_setfilesystemencoding(self):
old = sys.getfilesystemencoding()
try: