Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
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 socket
 import itertools
 import stat
+import locale
+import codecs
 try:
     import threading
 except ImportError:
@@ -1424,6 +1426,22 @@
             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 @@
         Win32KillTests,
         Win32SymlinkTests,
         FSEncodingTests,
+        DeviceEncodingTests,
         PidTests,
         LoginTests,
         LinkTests,