summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-02-29 23:31:31 (GMT)
committerBrett Cannon <brett@python.org>2012-02-29 23:31:31 (GMT)
commitefb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf (patch)
tree22dc683979e0dd42d049416797b756a5c6a053cd /Lib/test
parent54c32032aa28bdfead50714bf7861c98a9843597 (diff)
downloadcpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.zip
cpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.tar.gz
cpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.tar.bz2
Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index a0f13fd..5959d1e 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -22,6 +22,8 @@ import asynchat
import socket
import itertools
import stat
+import locale
+import codecs
try:
import threading
except ImportError:
@@ -1424,6 +1426,22 @@ class FSEncodingTests(unittest.TestCase):
self.assertEqual(os.fsdecode(bytesfn), fn)
+
+class DeviceEncodingTests(unittest.TestCase):
+
+ def test_bad_fd(self):
+ # Return None when an fd doesn't actually exist.
+ self.assertIsNone(os.device_encoding(123456))
+
+ @unittest.skipUnless(sys.platform.startswith('win') or
+ (hasattr(locale, 'nl_langinfo') and hasattr(locale, 'CODESET')),
+ 'test requires either Windows or nl_langinfo(CODESET)')
+ def test_device_encoding(self):
+ encoding = os.device_encoding(0)
+ self.assertIsNotNone(encoding)
+ self.assertTrue(codecs.lookup(encoding))
+
+
class PidTests(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
def test_getppid(self):
@@ -1923,6 +1941,7 @@ def test_main():
Win32KillTests,
Win32SymlinkTests,
FSEncodingTests,
+ DeviceEncodingTests,
PidTests,
LoginTests,
LinkTests,