Coverage for tests/test_parsers/test_annotations.py: 100.00%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Tests for [the `parsers.attributes` module][pytkdocs.parsers.attributes] on annotations."""
3import ast
5import pytest
7from pytkdocs.parsers.attributes import unparse_annotation
10def annotations(annotations_file):
11 with open(annotations_file) as fp:
12 for line in fp:
13 line = line.rstrip("\n")
14 yield line # annotation
15 yield line + " = 0" # annotated assignment
18@pytest.mark.parametrize("code", list(annotations("tests/fixtures/parsing/annotations.txt")))
19def test_annotation_to_text(code):
20 node = ast.parse(code, mode="single").body[0]
21 assert unparse_annotation(node.annotation) == code[3:].replace(" = 0", "") # remove "a: " prefix