Beispiel #1
0
    def test_subclasses(self):
        class A:
            pass

        class B(type):
            pass

        class C(A):
            pass

        class D(B):
            pass

        class G(C):
            pass

        class F(C):
            pass

        class E(C):
            pass

        mod = pdoc.Module(pdoc)
        self.assertEqual(
            [x.refname for x in pdoc.Class('A', mod, A).subclasses()],
            [mod.find_class(C).refname])
        self.assertEqual(
            [x.refname for x in pdoc.Class('B', mod, B).subclasses()],
            [mod.find_class(D).refname])
        self.assertEqual(
            [x.refname for x in pdoc.Class('C', mod, C).subclasses()],
            [mod.find_class(x).refname for x in (E, F, G)])
Beispiel #2
0
    def test_Class_docstring(self):
        class A:
            """foo"""

        class B:
            def __init__(self):
                """foo"""

        class C:
            """foo"""
            def __init__(self):
                """bar"""

        class D(C):
            """baz"""

        class E(C):
            def __init__(self):
                """baz"""

        mod = pdoc.Module(pdoc)
        self.assertEqual(pdoc.Class('A', mod, A).docstring, """foo""")
        self.assertEqual(pdoc.Class('B', mod, B).docstring, """foo""")
        self.assertEqual(pdoc.Class('C', mod, C).docstring, """foo\n\nbar""")
        self.assertEqual(pdoc.Class('D', mod, D).docstring, """baz\n\nbar""")
        self.assertEqual(pdoc.Class('E', mod, E).docstring, """foo\n\nbaz""")
Beispiel #3
0
    def test_Class_params(self):
        class C:
            def __init__(self, x):
                pass

        mod = pdoc.Module(pdoc)
        self.assertEqual(pdoc.Class('C', mod, C).params(), ['x'])
        with patch.dict(mod.obj.__pdoc__, {'C.__init__': False}):
            self.assertEqual(pdoc.Class('C', mod, C).params(), [])
Beispiel #4
0
    def test_Class_params(self):
        class C:
            def __init__(self, x):
                pass

        mod = pdoc.Module(pdoc)
        self.assertEqual(pdoc.Class('C', mod, C).params(), ['x'])
        with patch.dict(mod.obj.__pdoc__, {'C.__init__': False}):
            self.assertEqual(pdoc.Class('C', mod, C).params(), [])

        # test case for https://github.com/pdoc3/pdoc/issues/124
        class C2:
            __signature__ = inspect.signature(lambda a, b, c=None, *, d=1, e: None)

        self.assertEqual(pdoc.Class('C2', mod, C2).params(), ['a', 'b', 'c=None', '*', 'd=1', 'e'])
Beispiel #5
0
    def test_class_variables_docstring_not_from_obj(self):
        class C:
            vars_dont = 0
            but_clss_have_doc = int

        with self.assertWarns(UserWarning):
            doc = pdoc.Class('C', pdoc.Module('pdoc'), C)
        self.assertEqual(doc.doc['vars_dont'].docstring, '')
        self.assertIn('integer', doc.doc['but_clss_have_doc'].docstring)
Beispiel #6
0
    def test_Variable_type_annotation(self):
        import typing

        class Foobar:
            @property
            def prop(self) -> typing.Optional[int]:
                pass

        cls = pdoc.Class('Foobar', pdoc.Module(pdoc), Foobar)
        prop = cls.instance_variables()[0]
        self.assertEqual(prop.type_annotation(), 'Union[int,\N{NBSP}NoneType]')
Beispiel #7
0
 def test_builtin_methoddescriptors(self):
     import parser
     with self.assertWarns(UserWarning):
         c = pdoc.Class('STType', pdoc.Module(parser), parser.STType)
     self.assertIsInstance(c.doc['compile'], pdoc.Function)
Beispiel #8
0

clingo.ast.__spec__ = importlib.machinery.ModuleSpec("clingo.ast", None)

clingo.__pdoc__ = {}
for key, name, obj in SUB:
    clingo.__pdoc__[key] = re.sub(r"```python.*?class ({}(\([^)]*\))?):.*?```".format(name), "", obj.__doc__, flags=re.MULTILINE|re.DOTALL)

pdoc.tpl_lookup.directories.insert(0, './templates')
ctx = pdoc.Context()

cmod = pdoc.Module(clingo, context=ctx)
amod = pdoc.Module(clingo.ast, supermodule=cmod, context=ctx)
xmod = parse_aux()

cmod.doc["Application"] = pdoc.Class("Application", cmod, xmod.Application)
cmod.doc["Observer"] = pdoc.Class("Observer", cmod, xmod.Observer)
cmod.doc["Propagator"] = pdoc.Class("Propagator", cmod, xmod.Propagator)
cmod.doc["ast"] = amod
cmod.doc["__version__"] = pdoc.Variable("__version__", cmod, "__version__: str\n\nVersion of the clingo module (`'{}'`).".format(clingo.__version__))
cmod.doc["Infimum"] = pdoc.Variable("Infimum", cmod, '''Infimum: Symbol\n\nRepresents a symbol of type `clingo.SymbolType.Infimum`.''')
cmod.doc["Supremum"] = pdoc.Variable("Supremum", cmod, '''Supremum: Symbol\n\nRepresents a symbol of type `clingo.SymbolType.Supremum`.''')
pdoc.link_inheritance(ctx)

prefix = "../clingo/python-api/{}".format(".".join(clingo.__version__.split(".")[:2]))
cprefix = "../clingo/python-api/current"

os.makedirs("{}/ast".format(prefix), exist_ok=True)
os.makedirs("{}/ast".format(cprefix), exist_ok=True)

cmod_html = cmod.html(external_links=True)
Beispiel #9
0
#
# Copyright (C) 2020 Arm Mbed. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
"""Integration with https://github.com/ARMmbed/mbed-tools."""
import pdoc
from mbed_targets.env import Env

env_variables = pdoc.Class("Env", pdoc.Module("mbed_targets.env"),
                           Env).instance_variables()