1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import textwrap
import pytest
import globus_sdk
def test_locate_class_finds_transfer_client(sphinxext):
assert (
sphinxext.utils.locate_class("globus_sdk.TransferClient")
is globus_sdk.TransferClient
)
def test_locate_class_rejects_missing(sphinxext):
with pytest.raises(RuntimeError, match="MISSING is not a class name"):
sphinxext.utils.locate_class("globus_sdk.MISSING")
def test_read_sphinx_params(sphinxext):
docstring = """
preamble
:param param1: some doc on one line
:param param2: other doc
spanning multiple lines
:param param3: a doc
spanning
many
lines
:param param4: a doc
spanning lines
with a break in the middle ^
:param param5: another
:param param6: and a final one after some whitespace
epilogue
"""
params = sphinxext.utils.read_sphinx_params(docstring)
assert len(params) == 6
assert params[0] == ":param param1: some doc on one line"
assert params[1] == ":param param2: other doc\n spanning multiple lines"
assert params[2] == textwrap.dedent(
"""\
:param param3: a doc
spanning
many
lines"""
)
assert params[3] == textwrap.dedent(
"""\
:param param4: a doc
spanning lines
with a break in the middle ^"""
)
assert params[4] == ":param param5: another"
assert params[5] == ":param param6: and a final one after some whitespace"
# clear the cache after the test
# not essential, but reduces the risk that this impacts some future test
sphinxext.utils.read_sphinx_params.cache_clear()
|