Debian Codegraph @

tests/test_ext_autodoc/test_ext_autodoc_autoproperty.py

raw
1 """Test the autodoc extension.
2
3 This tests mainly the Documenters; the auto directives are tested in a test
4 source file translated by test_build.
5 """
6
7 from __future__ import annotations
8
9 import sys
10
11 import pytest
12
13 from tests.test_ext_autodoc.autodoc_util import do_autodoc
14
15 pytestmark = pytest.mark.usefixtures('inject_autodoc_root_into_sys_path')
16
17
18 def test_properties() -> None:
19 actual = do_autodoc('property', 'target.properties.Foo.prop1')
20 assert actual == [
21 '',
22 '.. py:property:: Foo.prop1',
23 ' :module: target.properties',
24 ' :type: int',
25 '',
26 ' docstring',
27 '',
28 ]
29
30
31 def test_class_properties() -> None:
32 actual = do_autodoc('property', 'target.properties.Foo.prop2')
33 assert actual == [
34 '',
35 '.. py:property:: Foo.prop2',
36 ' :module: target.properties',
37 ' :classmethod:',
38 ' :type: int',
39 '',
40 ' docstring',
41 '',
42 ]
43
44
45 def test_properties_with_type_comment() -> None:
46 actual = do_autodoc('property', 'target.properties.Foo.prop1_with_type_comment')
47 assert actual == [
48 '',
49 '.. py:property:: Foo.prop1_with_type_comment',
50 ' :module: target.properties',
51 ' :type: int',
52 '',
53 ' docstring',
54 '',
55 ]
56
57
58 def test_class_properties_with_type_comment() -> None:
59 actual = do_autodoc('property', 'target.properties.Foo.prop2_with_type_comment')
60 assert actual == [
61 '',
62 '.. py:property:: Foo.prop2_with_type_comment',
63 ' :module: target.properties',
64 ' :classmethod:',
65 ' :type: int',
66 '',
67 ' docstring',
68 '',
69 ]
70
71
72 def test_cached_properties() -> None:
73 actual = do_autodoc('property', 'target.cached_property.Foo.prop')
74 assert actual == [
75 '',
76 '.. py:property:: Foo.prop',
77 ' :module: target.cached_property',
78 ' :type: int',
79 '',
80 ]
81
82
83 def test_cached_properties_with_type_comment() -> None:
84 actual = do_autodoc('property', 'target.cached_property.Foo.prop_with_type_comment')
85 assert actual == [
86 '',
87 '.. py:property:: Foo.prop_with_type_comment',
88 ' :module: target.cached_property',
89 ' :type: int',
90 '',
91 ]
92
93
94 def test_property_with_undefined_annotation() -> None:
95 if sys.version_info[:2] >= (3, 14):
96 type_checking_only_name = 'TypeCheckingOnlyName'
97 else:
98 type_checking_only_name = 'int'
99
100 actual = do_autodoc(
101 'property', 'target.properties.Foo.prop3_with_undefined_anotation'
102 )
103 assert actual == [
104 '',
105 '.. py:property:: Foo.prop3_with_undefined_anotation',
106 ' :module: target.properties',
107 f' :type: {type_checking_only_name}',
108 '',
109 ' docstring',
110 '',
111 ]