Debian Codegraph @

tests/test_typing.py

raw symbols SCIP
1 import os
2 import types
3
4 import cairo
5
6
7 def test_typing():
8 mod = types.ModuleType("cairo")
9 stub = os.path.join(os.path.dirname(cairo.__file__), "__init__.pyi")
10 with open(stub, encoding="utf-8") as h:
11 code = compile(h.read(), stub, "exec")
12 exec(code, mod.__dict__)
13
14 def collect_names(t):
15 names = set()
16 for key, value in vars(t).items():
17 if key in ["XlibSurface", "XCBSurface", "Win32PrintingSurface",
18 "Win32Surface"]:
19 continue
20 if key.startswith("_"):
21 continue
22 if key.startswith("__") and key.endswith("__"):
23 continue
24 if getattr(value, "__module__", "") == "typing" or key == "Text":
25 continue
26 if isinstance(value, type):
27 names.add(key)
28
29 for k, v in vars(value).items():
30 if k.startswith("_"):
31 continue
32 name = f"{key}.{k}"
33 names.add(name)
34 else:
35 names.add(key)
36 return names
37
38 assert collect_names(cairo) <= collect_names(mod)