File: _test_embed_structseq.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (55 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (3)
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
import sys
import types
import unittest


# bpo-46417: Test that structseq types used by the sys module are still
# valid when Py_Finalize()/Py_Initialize() are called multiple times.
class TestStructSeq(unittest.TestCase):
    # test PyTypeObject members
    def check_structseq(self, obj_type):
        # ob_refcnt
        self.assertGreaterEqual(sys.getrefcount(obj_type), 1)
        # tp_base
        self.assertTrue(issubclass(obj_type, tuple))
        # tp_bases
        self.assertEqual(obj_type.__bases__, (tuple,))
        # tp_dict
        self.assertIsInstance(obj_type.__dict__, types.MappingProxyType)
        # tp_mro
        self.assertEqual(obj_type.__mro__, (obj_type, tuple, object))
        # tp_name
        self.assertIsInstance(type.__name__, str)
        # tp_subclasses
        self.assertEqual(obj_type.__subclasses__(), [])

    def test_sys_attrs(self):
        for attr_name in (
            'flags',          # FlagsType
            'float_info',     # FloatInfoType
            'hash_info',      # Hash_InfoType
            'int_info',       # Int_InfoType
            'thread_info',    # ThreadInfoType
            'version_info',   # VersionInfoType
        ):
            with self.subTest(attr=attr_name):
                attr = getattr(sys, attr_name)
                self.check_structseq(type(attr))

    def test_sys_funcs(self):
        func_names = ['get_asyncgen_hooks']  # AsyncGenHooksType
        if hasattr(sys, 'getwindowsversion'):
            func_names.append('getwindowsversion')  # WindowsVersionType
        for func_name in func_names:
            with self.subTest(func=func_name):
                func = getattr(sys, func_name)
                obj = func()
                self.check_structseq(type(obj))


try:
    unittest.main()
except SystemExit as exc:
    if exc.args[0] != 0:
        raise
print("Tests passed")