Debian Codegraph @

tests/test_docs.py

raw
1 # Copyright (c) Meta Platforms, Inc. and affiliates.
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 import importlib
5 import pkgutil
6 import pydoc
7 import types
8
9 import drgn
10 import drgn.helpers.common
11 import drgn.helpers.linux
12 from tests import TestCase
13
14
15 class TestDocs(TestCase):
16 def test_render(self):
17 pydoc.render_doc(drgn)
18
19 def test_helper_exports(self):
20 for package in (drgn.helpers.common, drgn.helpers.linux):
21 for module_info in pkgutil.iter_modules(
22 package.__path__, prefix=package.__name__ + "."
23 ):
24 with self.subTest(module=module_info.name):
25 submodule = importlib.import_module(module_info.name)
26 expected = set()
27 for name in dir(submodule):
28 attr = getattr(submodule, name)
29 # Documented functions defined in the given module
30 # should be in __all__. This won't catch non-function
31 # callables or re-exports, but it's close enough.
32 if (
33 isinstance(
34 attr, (types.FunctionType, types.BuiltinFunctionType)
35 )
36 and getattr(attr, "__module__", None) == module_info.name
37 and getattr(attr, "__doc__", None)
38 ):
39 expected.add(name)
40 missing = expected - set(getattr(submodule, "__all__", ()))
41 if missing:
42 self.fail(
43 f"{module_info.name}.__all__ is missing {sorted(missing)}"
44 )