[Python-checkins] r81920 - python/branches/py3k/Lib/test/test_sys.py

victor.stinner python-checkins at python.org
Sat Jun 12 01:06:13 CEST 2010


Author: victor.stinner
Date: Sat Jun 12 01:06:13 2010
New Revision: 81920

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


Modified:
   python/branches/py3k/Lib/test/test_sys.py

Modified: python/branches/py3k/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sys.py	(original)
+++ python/branches/py3k/Lib/test/test_sys.py	Sat Jun 12 01:06:13 2010
@@ -863,21 +863,34 @@
         # 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
+        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()
-        self.assertEqual(fs_encoding, 'utf-8')
+        check_fsencoding(fs_encoding)
 
         # Even in C locale
-        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')
+        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()


More information about the Python-checkins mailing list