File: test_documentation.py

package info (click to toggle)
python-aristaproto 1.2%2Breally0.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,600 kB
  • sloc: python: 6,521; java: 106; xml: 84; makefile: 6
file content (37 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (2)
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
import ast
import inspect


def check(generated_doc: str, type: str) -> None:
    assert f"Documentation of {type} 1" in generated_doc
    assert "other line 1" in generated_doc
    assert f"Documentation of {type} 2" in generated_doc
    assert "other line 2" in generated_doc
    assert f"Documentation of {type} 3" in generated_doc


def test_documentation() -> None:
    from .output_aristaproto.documentation import (
        Enum,
        ServiceBase,
        ServiceStub,
        Test,
    )

    check(Test.__doc__, "message")

    source = inspect.getsource(Test)
    tree = ast.parse(source)
    check(tree.body[0].body[2].value.value, "field")

    check(Enum.__doc__, "enum")

    source = inspect.getsource(Enum)
    tree = ast.parse(source)
    check(tree.body[0].body[2].value.value, "variant")

    check(ServiceBase.__doc__, "service")
    check(ServiceBase.get.__doc__, "method")

    check(ServiceStub.__doc__, "service")
    check(ServiceStub.get.__doc__, "method")