Skip to content

Commit abadd9e

Browse files
committed
Add a test for the @cached_property hack
1 parent 97432db commit abadd9e

5 files changed

Lines changed: 152 additions & 174 deletions

File tree

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ tests = [
4848
"pympler",
4949
"pytest",
5050
"pytest-xdist[psutil]",
51+
"sphinx",
52+
"sphinx-notfound-page"
53+
"sphinx-basic-ng",
54+
"sphinxcontrib-applehelp",
55+
"sphinxcontrib-devhelp",
56+
"sphinxcontrib-htmlhelp",
57+
"sphinxcontrib-jsmath",
58+
"sphinxcontrib-serializinghtml",
59+
"sphinxcontrib-towncrier",
60+
"myst-parser",
5161
]
5262
cov = [{ include-group = "tests" }, "coverage[toml]"]
5363
pyright = ["pyright", { include-group = "tests" }]

tests/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. autoclass:: tests.test_slots.SphinxDocTest
2+
3+
.. autoproperty:: documented

tests/index.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class tests.test_slots.SphinxDocTest
2+
3+
Test that slotted cached_property shows up in Sphinx docs
4+
5+
property documented
6+
7+
A very well documented function

tests/test_slots.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import functools
88
import pickle
99
import weakref
10-
10+
from pathlib import Path
11+
from tempfile import TemporaryDirectory
1112
from unittest import mock
1213

1314
import pytest
15+
try:
16+
from sphinx.application import Sphinx
17+
except ImportError:
18+
Sphinx = None
1419

1520
import attr
1621
import attrs
@@ -735,6 +740,29 @@ def f(self):
735740
assert B(11).f == 121
736741
assert B(17).f == 289
737742

743+
@attr.s(slots=True)
744+
class SphinxDocTest:
745+
"""Test that slotted cached_property shows up in Sphinx docs"""
746+
747+
@functools.cached_property
748+
def documented(self):
749+
"""A very well documented function"""
750+
return True
751+
752+
753+
@pytest.mark.skipif(Sphinx is None, reason="Sphinx is not installed")
754+
def test_sphinx_autodocuments_cached_property():
755+
here = Path(__file__).parent
756+
with TemporaryDirectory() as td:
757+
tmp_path = Path(td)
758+
app = Sphinx(here, here.parent.joinpath("docs"), tmp_path, tmp_path, "text")
759+
app.build(force_all=True)
760+
with (
761+
tmp_path.joinpath("index.txt").open() as written,
762+
Path(__file__).parent.joinpath("index.txt").open() as good,
763+
):
764+
assert written.read() == good.read()
765+
738766

739767
def test_slots_cached_property_allows_call():
740768
"""

0 commit comments

Comments
 (0)