aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorPaul Monson <paulmon@users.noreply.github.com>2019-04-25 11:36:45 -0700
committerSteve Dower <steve.dower@python.org>2019-04-25 18:36:45 +0000
commit62dfd7d6fe11bfa0cd1d7376382c8e7b1275e38c (patch)
treef59fcebb25702acbde504865f1a483ab7ac80954 /Lib/test/test_codecs.py
parent8c3ecc6bacc8d0cd534f2b5b53ed962dd1368c7b (diff)
downloadcpython-62dfd7d6fe11bfa0cd1d7376382c8e7b1275e38c.tar.gz
cpython-62dfd7d6fe11bfa0cd1d7376382c8e7b1275e38c.zip
bpo-35920: Windows 10 ARM32 platform support (GH-11774)
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 05843c54bd5..027a84e275e 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -27,6 +27,26 @@ def coding_checker(self, coder):
self.assertEqual(coder(input), (expect, len(input)))
return check
+# On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
+def is_code_page_present(cp):
+ from ctypes import POINTER, WINFUNCTYPE, windll, WinError, Structure, WinDLL
+ from ctypes.wintypes import BOOL, UINT, BYTE, WCHAR, UINT, DWORD
+
+ MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.
+ MAX_DEFAULTCHAR = 2 # single or double byte
+ MAX_PATH = 260
+ class CPINFOEXW(ctypes.Structure):
+ _fields_ = [("MaxCharSize", UINT),
+ ("DefaultChar", BYTE*MAX_DEFAULTCHAR),
+ ("LeadByte", BYTE*MAX_LEADBYTES),
+ ("UnicodeDefaultChar", WCHAR),
+ ("CodePage", UINT),
+ ("CodePageName", WCHAR*MAX_PATH)]
+
+ prototype = WINFUNCTYPE(BOOL, UINT, DWORD, POINTER(CPINFOEXW))
+ GetCPInfoEx = prototype(("GetCPInfoExW", WinDLL("kernel32")))
+ info = CPINFOEXW()
+ return GetCPInfoEx(cp, 0, info)
class Queue(object):
"""
@@ -3078,9 +3098,19 @@ class CodePageTest(unittest.TestCase):
def test_code_page_decode_flags(self):
# Issue #36312: For some code pages (e.g. UTF-7) flags for
# MultiByteToWideChar() must be set to 0.
+ if support.verbose:
+ sys.stdout.write('\n')
for cp in (50220, 50221, 50222, 50225, 50227, 50229,
*range(57002, 57011+1), 65000):
- self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3))
+ # On small versions of Windows like Windows IoT
+ # not all codepages are present.
+ # A missing codepage causes an OSError exception
+ # so check for the codepage before decoding
+ if is_code_page_present(cp):
+ self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3), f'cp{cp}')
+ else:
+ if support.verbose:
+ print(f" skipping cp={cp}")
self.assertEqual(codecs.code_page_decode(42, b'abc'),
('\uf061\uf062\uf063', 3))