Coverage for tests/test_parsers/test_annotations.py: 100.00%
14 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-09 17:28 +0100
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-09 17:28 +0100
1"""Tests for [the `parsers.attributes` module][pytkdocs.parsers.attributes] on annotations."""
3import ast
4from collections.abc import Iterator
6import pytest
8from pytkdocs.parsers.attributes import unparse_annotation
11def annotations(annotations_file: str) -> Iterator[str]:
12 with open(annotations_file) as fp:
13 for line in fp:
14 line = line.rstrip("\n") # noqa: PLW2901
15 yield line # annotation
16 yield line + " = 0" # annotated assignment
19@pytest.mark.parametrize("code", list(annotations("tests/fixtures/parsing/annotations.txt")))
20def test_annotation_to_text(code: str) -> None:
21 node = ast.parse(code, mode="single").body[0]
22 assert unparse_annotation(node.annotation) == code[3:].replace(" = 0", "") # type: ignore[attr-defined]