Skip to content

Commit

Permalink
Merge f416b1a into 6a56c36
Browse files Browse the repository at this point in the history
  • Loading branch information
musicinmybrain committed Feb 16, 2024
2 parents 6a56c36 + f416b1a commit 71a5a66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion shapely/decorators.py
Expand Up @@ -39,7 +39,7 @@ def wrapped(*args, **kwargs):
# Insert the message at the first double newline
position = doc.find("\n\n") + 2
# Figure out the indentation level
indent = 2
indent = 0
while True:
if doc[position + indent] == " ":
indent += 1
Expand Down
20 changes: 15 additions & 5 deletions shapely/tests/test_misc.py
@@ -1,5 +1,6 @@
import os
import sys
from inspect import cleandoc
from itertools import chain
from string import ascii_letters, digits
from unittest import mock
Expand Down Expand Up @@ -82,13 +83,22 @@ def func(self):
"""


expected_docstring = """Docstring that will be mocked.
def expected_docstring(**kwds):
doc = """Docstring that will be mocked.
{indent}A multiline.
{indent}.. note:: 'func' requires at least GEOS {version}.
{indent}Some description.
{indent}"""
{indent}""".format(
**kwds
)
if sys.version_info[:2] >= (3, 13):
# There are subtle differences between inspect.cleandoc() and
# _PyCompile_CleanDoc(). Most significantly, the latter does not remove
# leading or trailing blank lines.
return cleandoc(doc) + "\n"
return doc


@pytest.mark.parametrize("version", ["3.10.0", "3.10.1", "3.9.2"])
Expand All @@ -104,23 +114,23 @@ def test_requires_geos_not_ok(version, mocked_geos_version):
with pytest.raises(shapely.errors.UnsupportedGEOSVersionError):
wrapped()

assert wrapped.__doc__ == expected_docstring.format(version=version, indent=" " * 4)
assert wrapped.__doc__ == expected_docstring(version=version, indent=" " * 4)


@pytest.mark.parametrize("version", ["3.9.0", "3.10.0"])
def test_requires_geos_doc_build(version, mocked_geos_version, sphinx_doc_build):
"""The requires_geos decorator always adapts the docstring."""
wrapped = requires_geos(version)(func)

assert wrapped.__doc__ == expected_docstring.format(version=version, indent=" " * 4)
assert wrapped.__doc__ == expected_docstring(version=version, indent=" " * 4)


@pytest.mark.parametrize("version", ["3.9.0", "3.10.0"])
def test_requires_geos_method(version, mocked_geos_version, sphinx_doc_build):
"""The requires_geos decorator adjusts methods docstrings correctly"""
wrapped = requires_geos(version)(SomeClass.func)

assert wrapped.__doc__ == expected_docstring.format(version=version, indent=" " * 8)
assert wrapped.__doc__ == expected_docstring(version=version, indent=" " * 8)


@multithreading_enabled
Expand Down

0 comments on commit 71a5a66

Please sign in to comment.