- Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy path_test_embed_structseq.py
59 lines (53 loc) · 1.99 KB
/
_test_embed_structseq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
importsys
importtypes
# Note: This test file can't import `unittest` since the runtime can't
# currently guarantee that it will not leak memory. Doing so will mark
# the test as passing but with reference leaks. This can safely import
# the `unittest` library once there's a strict guarantee of no leaks
# during runtime shutdown.
# bpo-46417: Test that structseq types used by the sys module are still
# valid when Py_Finalize()/Py_Initialize() are called multiple times.
classTestStructSeq:
# test PyTypeObject members
def_check_structseq(self, obj_type):
# ob_refcnt
assertsys.getrefcount(obj_type) >1
# tp_base
assertissubclass(obj_type, tuple)
# tp_bases
assertobj_type.__bases__== (tuple,)
# tp_dict
assertisinstance(obj_type.__dict__, types.MappingProxyType)
# tp_mro
assertobj_type.__mro__== (obj_type, tuple, object)
# tp_name
assertisinstance(type.__name__, str)
# tp_subclasses
assertobj_type.__subclasses__() == []
deftest_sys_attrs(self):
forattr_namein (
'flags', # FlagsType
'float_info', # FloatInfoType
'hash_info', # Hash_InfoType
'int_info', # Int_InfoType
'thread_info', # ThreadInfoType
'version_info', # VersionInfoType
):
attr=getattr(sys, attr_name)
self._check_structseq(type(attr))
deftest_sys_funcs(self):
func_names= ['get_asyncgen_hooks'] # AsyncGenHooksType
ifhasattr(sys, 'getwindowsversion'):
func_names.append('getwindowsversion') # WindowsVersionType
forfunc_nameinfunc_names:
func=getattr(sys, func_name)
obj=func()
self._check_structseq(type(obj))
try:
tests=TestStructSeq()
tests.test_sys_attrs()
tests.test_sys_funcs()
exceptSystemExitasexc:
ifexc.args[0] !=0:
raise
print("Tests passed")