summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpicnixz <10796600+picnixz@users.noreply.github.com>2023-04-06 23:56:17 +0200
committerGitHub <noreply@github.com>2023-04-06 22:56:17 +0100
commitaba392d87f5b7cc9954aa2666805a80cd593b2eb (patch)
treebb4dab651f66725bb98c2daba06abb5eab012fbf /tests
parent26eb2ef7c4fe3de17b16bffb47a2eb290445cf16 (diff)
downloadsphinx-git-aba392d87f5b7cc9954aa2666805a80cd593b2eb.tar.gz
Support type comments in ``PropertyDocumenter`` (#11298)
Diffstat (limited to 'tests')
-rw-r--r--tests/roots/test-ext-autodoc/target/cached_property.py5
-rw-r--r--tests/roots/test-ext-autodoc/target/properties.py11
-rw-r--r--tests/test_ext_autodoc.py5
-rw-r--r--tests/test_ext_autodoc_autoclass.py15
-rw-r--r--tests/test_ext_autodoc_autoproperty.py41
5 files changed, 77 insertions, 0 deletions
diff --git a/tests/roots/test-ext-autodoc/target/cached_property.py b/tests/roots/test-ext-autodoc/target/cached_property.py
index 63ec09f8e..712d1d917 100644
--- a/tests/roots/test-ext-autodoc/target/cached_property.py
+++ b/tests/roots/test-ext-autodoc/target/cached_property.py
@@ -5,3 +5,8 @@ class Foo:
@cached_property
def prop(self) -> int:
return 1
+
+ @cached_property
+ def prop_with_type_comment(self):
+ # type: () -> int
+ return 1
diff --git a/tests/roots/test-ext-autodoc/target/properties.py b/tests/roots/test-ext-autodoc/target/properties.py
index 561daefb8..018f51ee4 100644
--- a/tests/roots/test-ext-autodoc/target/properties.py
+++ b/tests/roots/test-ext-autodoc/target/properties.py
@@ -9,3 +9,14 @@ class Foo:
@property
def prop2(self) -> int:
"""docstring"""
+
+ @property
+ def prop1_with_type_comment(self):
+ # type: () -> int
+ """docstring"""
+
+ @classmethod
+ @property
+ def prop2_with_type_comment(self):
+ # type: () -> int
+ """docstring"""
diff --git a/tests/test_ext_autodoc.py b/tests/test_ext_autodoc.py
index 64347bbc6..1023323aa 100644
--- a/tests/test_ext_autodoc.py
+++ b/tests/test_ext_autodoc.py
@@ -1089,6 +1089,11 @@ def test_autodoc_cached_property(app):
' :module: target.cached_property',
' :type: int',
'',
+ '',
+ ' .. py:property:: Foo.prop_with_type_comment',
+ ' :module: target.cached_property',
+ ' :type: int',
+ '',
]
diff --git a/tests/test_ext_autodoc_autoclass.py b/tests/test_ext_autodoc_autoclass.py
index 2c70104ea..fd4e4165b 100644
--- a/tests/test_ext_autodoc_autoclass.py
+++ b/tests/test_ext_autodoc_autoclass.py
@@ -213,6 +213,13 @@ def test_properties(app):
' docstring',
'',
'',
+ ' .. py:property:: Foo.prop1_with_type_comment',
+ ' :module: target.properties',
+ ' :type: int',
+ '',
+ ' docstring',
+ '',
+ '',
' .. py:property:: Foo.prop2',
' :module: target.properties',
' :classmethod:',
@@ -220,6 +227,14 @@ def test_properties(app):
'',
' docstring',
'',
+ '',
+ ' .. py:property:: Foo.prop2_with_type_comment',
+ ' :module: target.properties',
+ ' :classmethod:',
+ ' :type: int',
+ '',
+ ' docstring',
+ '',
]
diff --git a/tests/test_ext_autodoc_autoproperty.py b/tests/test_ext_autodoc_autoproperty.py
index f982144a9..ca8b981d3 100644
--- a/tests/test_ext_autodoc_autoproperty.py
+++ b/tests/test_ext_autodoc_autoproperty.py
@@ -39,6 +39,35 @@ def test_class_properties(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_properties_with_type_comment(app):
+ actual = do_autodoc(app, 'property', 'target.properties.Foo.prop1_with_type_comment')
+ assert list(actual) == [
+ '',
+ '.. py:property:: Foo.prop1_with_type_comment',
+ ' :module: target.properties',
+ ' :type: int',
+ '',
+ ' docstring',
+ '',
+ ]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_class_properties_with_type_comment(app):
+ actual = do_autodoc(app, 'property', 'target.properties.Foo.prop2_with_type_comment')
+ assert list(actual) == [
+ '',
+ '.. py:property:: Foo.prop2_with_type_comment',
+ ' :module: target.properties',
+ ' :classmethod:',
+ ' :type: int',
+ '',
+ ' docstring',
+ '',
+ ]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_cached_properties(app):
actual = do_autodoc(app, 'property', 'target.cached_property.Foo.prop')
assert list(actual) == [
@@ -48,3 +77,15 @@ def test_cached_properties(app):
' :type: int',
'',
]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_cached_properties_with_type_comment(app):
+ actual = do_autodoc(app, 'property', 'target.cached_property.Foo.prop_with_type_comment')
+ assert list(actual) == [
+ '',
+ '.. py:property:: Foo.prop_with_type_comment',
+ ' :module: target.cached_property',
+ ' :type: int',
+ '',
+ ]