python-betterproto/tests/test_documentation.py
Adrien 1741a126b3
Add all kinds of comments (#632)
* Add all kinds of comments

* Format

* Fix get_comment

* Improve test

* Lint
2024-11-07 03:11:53 +00:00

38 lines
986 B
Python

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_betterproto.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")