Skip to content

Commit 48c8f26

Browse files
Update the ctypes test.
1 parent c7074f2 commit 48c8f26

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

Lib/ctypes/test/test_values.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,37 @@ class struct_frozen(Structure):
5656
("size", c_int)]
5757
FrozenTable = POINTER(struct_frozen)
5858

59-
ft = FrozenTable.in_dll(pythonapi, "PyImport_FrozenModules")
60-
# ft is a pointer to the struct_frozen entries:
6159
modules = []
62-
for entry in ft:
63-
# This is dangerous. We *can* iterate over a pointer, but
64-
# the loop will not terminate (maybe with an access
65-
# violation;-) because the pointer instance has no size.
66-
if entry.name is None:
67-
break
68-
modname = entry.name.decode("ascii")
69-
modules.append(modname)
70-
with self.subTest(modname):
71-
# Do a sanity check on entry.size and entry.code.
72-
self.assertGreater(abs(entry.size), 10)
73-
self.assertTrue([entry.code[i] for i in range(abs(entry.size))])
74-
# Check the module's package-ness.
75-
with import_helper.frozen_modules():
76-
spec = importlib.util.find_spec(modname)
77-
if entry.size < 0:
78-
# It's a package.
79-
self.assertIsNotNone(spec.submodule_search_locations)
80-
else:
81-
self.assertIsNone(spec.submodule_search_locations)
60+
for group in ["Bootstrap", "Stdlib", "Test"]:
61+
ft = FrozenTable.in_dll(pythonapi, f"_PyImport_Frozen{group}")
62+
# ft is a pointer to the struct_frozen entries:
63+
for entry in ft:
64+
# This is dangerous. We *can* iterate over a pointer, but
65+
# the loop will not terminate (maybe with an access
66+
# violation;-) because the pointer instance has no size.
67+
if entry.name is None:
68+
break
69+
modname = entry.name.decode("ascii")
70+
modules.append(modname)
71+
with self.subTest(modname):
72+
# Do a sanity check on entry.size and entry.code.
73+
self.assertGreater(abs(entry.size), 10)
74+
self.assertTrue([entry.code[i] for i in range(abs(entry.size))])
75+
# Check the module's package-ness.
76+
with import_helper.frozen_modules():
77+
spec = importlib.util.find_spec(modname)
78+
if entry.size < 0:
79+
# It's a package.
80+
self.assertIsNotNone(spec.submodule_search_locations)
81+
else:
82+
self.assertIsNone(spec.submodule_search_locations)
8283

8384
with import_helper.frozen_modules():
8485
expected = _imp._frozen_module_names()
8586
self.maxDiff = None
86-
self.assertEqual(modules, expected, "PyImport_FrozenModules example "
87-
"in Doc/library/ctypes.rst may be out of date")
87+
self.assertEqual(modules, expected,
88+
"_PyImport_FrozenBootstrap example "
89+
"in Doc/library/ctypes.rst may be out of date")
8890

8991
from ctypes import _pointer_type_cache
9092
del _pointer_type_cache[struct_frozen]

0 commit comments

Comments
 (0)