2018-12-14 01:52:06 +00:00
|
|
|
import io
|
|
|
|
import os
|
2020-07-12 02:27:59 +00:00
|
|
|
import re
|
2018-12-14 01:52:06 +00:00
|
|
|
import shutil
|
2019-04-06 18:16:40 +00:00
|
|
|
import sys
|
2021-04-04 02:01:27 +00:00
|
|
|
from unittest.mock import patch, Mock, call
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
import sphinx
|
|
|
|
from sphinx.application import Sphinx
|
2019-02-05 05:21:32 +00:00
|
|
|
import sphinx.util.logging
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-09-04 21:44:35 +00:00
|
|
|
from autoapi.mappers.python import (
|
|
|
|
PythonModule,
|
|
|
|
PythonFunction,
|
|
|
|
PythonClass,
|
|
|
|
PythonData,
|
|
|
|
PythonMethod,
|
|
|
|
)
|
|
|
|
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2021-06-26 03:14:33 +00:00
|
|
|
def rebuild(confoverrides=None, confdir=".", **kwargs):
|
2020-10-26 23:12:59 +00:00
|
|
|
app = Sphinx(
|
|
|
|
srcdir=".",
|
2021-06-26 03:14:33 +00:00
|
|
|
confdir=confdir,
|
2020-10-26 23:12:59 +00:00
|
|
|
outdir="_build/text",
|
|
|
|
doctreedir="_build/.doctrees",
|
|
|
|
buildername="text",
|
|
|
|
confoverrides=confoverrides,
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
app.build()
|
|
|
|
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
@pytest.fixture(scope="class")
|
2018-12-14 01:52:06 +00:00
|
|
|
def builder():
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
2020-07-12 02:53:00 +00:00
|
|
|
def build(test_dir, confoverrides=None, **kwargs):
|
2019-01-27 05:20:45 +00:00
|
|
|
os.chdir("tests/python/{0}".format(test_dir))
|
2020-10-26 23:12:59 +00:00
|
|
|
rebuild(confoverrides=confoverrides, **kwargs)
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
yield build
|
|
|
|
|
|
|
|
try:
|
2019-01-27 05:20:45 +00:00
|
|
|
shutil.rmtree("_build")
|
2018-12-14 01:52:06 +00:00
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestSimpleModule:
|
2019-01-27 05:20:45 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
2018-12-14 01:52:06 +00:00
|
|
|
def built(self, builder):
|
2021-06-26 02:30:54 +00:00
|
|
|
builder(
|
|
|
|
"pyexample",
|
|
|
|
warningiserror=True,
|
|
|
|
confoverrides={"suppress_warnings": ["app"]},
|
|
|
|
)
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
def test_integration(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
self.check_integration("_build/text/autoapi/example/index.txt")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
def test_manual_directives(self):
|
2019-08-11 06:00:29 +00:00
|
|
|
example_path = "_build/text/manualapi.txt"
|
2018-12-14 01:52:06 +00:00
|
|
|
# The manual directives should contain the same information
|
2019-08-11 06:00:29 +00:00
|
|
|
self.check_integration(example_path)
|
|
|
|
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2020-10-03 19:21:25 +00:00
|
|
|
assert "@example.decorator_okay" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
def check_integration(self, example_path):
|
2019-01-27 05:20:45 +00:00
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "class example.Foo" in example_file
|
|
|
|
assert "class Meta" in example_file
|
|
|
|
assert "attr2" in example_file
|
|
|
|
assert "This is the docstring of an instance attribute." in example_file
|
|
|
|
assert "method_okay(self, foo=None, bar=None)" in example_file
|
|
|
|
assert "method_multiline(self, foo=None, bar=None, baz=None)" in example_file
|
|
|
|
assert "method_tricky(self, foo=None, bar=dict(foo=1, bar=2))" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
# Are constructor arguments from the class docstring parsed?
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Set an attribute" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
# "self" should not be included in constructor arguments
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Foo(self" not in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2020-05-16 23:24:16 +00:00
|
|
|
# Overridden methods without their own docstring
|
|
|
|
# should inherit the parent's docstring
|
|
|
|
assert example_file.count("This method should parse okay") == 2
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert not os.path.exists("_build/text/autoapi/method_multiline")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2021-08-01 01:06:12 +00:00
|
|
|
# Inherited constructor docstrings should be included in a merged
|
|
|
|
# (autoapi_python_class_content="both") class docstring only once.
|
|
|
|
assert example_file.count("One __init__.") == 3
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
index_path = "_build/text/index.txt"
|
|
|
|
with io.open(index_path, encoding="utf8") as index_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
index_file = index_handle.read()
|
|
|
|
|
2019-04-06 18:15:18 +00:00
|
|
|
assert "API Reference" in index_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Foo" in index_file
|
|
|
|
assert "Meta" in index_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
def test_napoleon_integration_not_loaded(self, builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
# Check that docstrings are not transformed without napoleon loaded
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Args" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Returns" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2020-01-25 22:21:56 +00:00
|
|
|
def test_show_inheritance(self, builder):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "Bases:" in example_file
|
|
|
|
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2021-06-26 03:14:33 +00:00
|
|
|
class TestMovedConfPy(TestSimpleModule):
|
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder(
|
|
|
|
"pymovedconfpy",
|
|
|
|
confdir="confpy",
|
|
|
|
warningiserror=True,
|
|
|
|
confoverrides={"suppress_warnings": ["app"]},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-28 00:09:09 +00:00
|
|
|
class TestSimpleModuleDifferentPrimaryDomain:
|
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder(
|
|
|
|
"pyexample",
|
|
|
|
warningiserror=True,
|
|
|
|
confoverrides={
|
|
|
|
"autoapi_options": [
|
|
|
|
"members",
|
|
|
|
"undoc-members",
|
|
|
|
"private-members",
|
|
|
|
"special-members",
|
|
|
|
"imported-members",
|
|
|
|
],
|
|
|
|
"primary_domain": "cpp",
|
|
|
|
"suppress_warnings": ["app"],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_success(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestSimpleStubModule:
|
2019-04-06 18:16:40 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("pyiexample")
|
|
|
|
|
|
|
|
def test_integration(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2020-09-01 04:17:57 +00:00
|
|
|
# Are pyi files preferred
|
|
|
|
assert "DoNotFindThis" not in example_file
|
|
|
|
|
2019-04-06 18:16:40 +00:00
|
|
|
assert "class example.Foo" in example_file
|
|
|
|
assert "class Meta" in example_file
|
|
|
|
assert "Another class var docstring" in example_file
|
|
|
|
assert "A class var without a value." in example_file
|
|
|
|
assert "method_okay(self, foo=None, bar=None)" in example_file
|
|
|
|
assert "method_multiline(self, foo=None, bar=None, baz=None)" in example_file
|
|
|
|
assert "method_without_docstring(self)" in example_file
|
|
|
|
|
|
|
|
# Are constructor arguments from the class docstring parsed?
|
|
|
|
assert "Set an attribute" in example_file
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestSimpleStubModuleNotPreferred:
|
2020-09-01 04:17:57 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("pyiexample2")
|
|
|
|
|
|
|
|
def test_integration(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
# Are py files preferred
|
|
|
|
assert "DoNotFindThis" not in example_file
|
|
|
|
|
|
|
|
assert "Foo" in example_file
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestPy3Module:
|
2019-04-22 04:45:08 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
2019-07-18 03:58:00 +00:00
|
|
|
builder("py3example")
|
2019-04-22 04:45:08 +00:00
|
|
|
|
2021-02-01 00:12:19 +00:00
|
|
|
def test_integration(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "Initialize self" not in example_file
|
|
|
|
assert "a new type" not in example_file
|
|
|
|
|
2019-07-18 03:58:00 +00:00
|
|
|
def test_annotations(self):
|
2019-04-22 04:45:08 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2021-02-15 14:07:02 +00:00
|
|
|
assert "software = sphinx" in example_file
|
|
|
|
assert "code_snippet = Multiline-String" in example_file
|
|
|
|
|
2019-04-22 04:45:08 +00:00
|
|
|
assert "max_rating :int = 10" in example_file
|
|
|
|
assert "is_valid" in example_file
|
|
|
|
|
|
|
|
assert "ratings" in example_file
|
|
|
|
assert "List[int]" in example_file
|
|
|
|
|
|
|
|
assert "Dict[int, str]" in example_file
|
|
|
|
|
2019-08-08 06:23:21 +00:00
|
|
|
assert "start: int" in example_file
|
2019-04-22 04:45:08 +00:00
|
|
|
assert "Iterable[int]" in example_file
|
|
|
|
|
|
|
|
assert "List[Union[str, int]]" in example_file
|
|
|
|
|
2019-08-08 06:23:21 +00:00
|
|
|
assert "not_yet_a: A" in example_file
|
2021-01-31 18:14:52 +00:00
|
|
|
assert "imported: example2.B" in example_file
|
|
|
|
assert "-> example2.B" in example_file
|
|
|
|
|
2019-04-22 04:45:08 +00:00
|
|
|
assert "is_an_a" in example_file
|
|
|
|
assert "ClassVar" in example_file
|
|
|
|
|
|
|
|
assert "instance_var" in example_file
|
|
|
|
|
|
|
|
assert "global_a :A" in example_file
|
|
|
|
|
2020-10-03 19:21:25 +00:00
|
|
|
assert "my_method(self) -> str" in example_file
|
2020-07-12 02:27:59 +00:00
|
|
|
|
2020-10-14 21:07:55 +00:00
|
|
|
assert "class example.SomeMetaclass" in example_file
|
|
|
|
|
2020-08-06 07:38:29 +00:00
|
|
|
def test_overload(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "overloaded_func(a: float" in example_file
|
|
|
|
assert "overloaded_func(a: str" in example_file
|
|
|
|
assert "overloaded_func(a: Union" not in example_file
|
|
|
|
assert "Overloaded function" in example_file
|
|
|
|
|
|
|
|
assert "overloaded_method(self, a: float" in example_file
|
|
|
|
assert "overloaded_method(self, a: str" in example_file
|
|
|
|
assert "overloaded_method(self, a: Union" not in example_file
|
|
|
|
assert "Overloaded method" in example_file
|
|
|
|
|
|
|
|
assert "overloaded_class_method(cls, a: float" in example_file
|
|
|
|
assert "overloaded_class_method(cls, a: str" in example_file
|
|
|
|
assert "overloaded_class_method(cls, a: Union" not in example_file
|
|
|
|
assert "Overloaded method" in example_file
|
|
|
|
|
|
|
|
assert "undoc_overloaded_func" in example_file
|
|
|
|
assert "undoc_overloaded_method" in example_file
|
|
|
|
|
2021-01-31 23:34:40 +00:00
|
|
|
assert "C(a: int" in example_file
|
|
|
|
assert "C(a: float" in example_file
|
|
|
|
assert "C(a: str" not in example_file
|
|
|
|
assert "C(self, a: int" not in example_file
|
|
|
|
assert "C(self, a: float" not in example_file
|
|
|
|
assert "C(self, a: str" not in example_file
|
|
|
|
|
2019-07-18 03:58:00 +00:00
|
|
|
def test_async(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2020-10-03 19:21:25 +00:00
|
|
|
assert "async async_method" in example_file
|
|
|
|
assert "async example.async_function" in example_file
|
2019-07-18 03:58:00 +00:00
|
|
|
|
2019-04-22 04:45:08 +00:00
|
|
|
|
2020-08-06 07:38:29 +00:00
|
|
|
def test_py3_hiding_undoc_overloaded_members(builder):
|
|
|
|
confoverrides = {"autoapi_options": ["members", "special-members"]}
|
|
|
|
builder("py3example", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "overloaded_func" in example_file
|
|
|
|
assert "overloaded_method" in example_file
|
|
|
|
assert "undoc_overloaded_func" not in example_file
|
|
|
|
assert "undoc_overloaded_method" not in example_file
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestAnnotationCommentsModule:
|
2019-04-22 04:45:08 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("pyannotationcommentsexample")
|
|
|
|
|
|
|
|
def test_integration(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "max_rating :int = 10" in example_file
|
|
|
|
|
|
|
|
assert "ratings" in example_file
|
|
|
|
assert "List[int]" in example_file
|
|
|
|
|
|
|
|
assert "Dict[int, str]" in example_file
|
|
|
|
|
2019-08-08 06:23:21 +00:00
|
|
|
# When astroid>2.2.5
|
|
|
|
# assert "start: int" in example_file
|
|
|
|
# assert "end: int" in example_file
|
2019-04-22 04:45:08 +00:00
|
|
|
assert "Iterable[int]" in example_file
|
|
|
|
|
|
|
|
assert "List[Union[str, int]]" in example_file
|
|
|
|
|
2019-08-08 06:23:21 +00:00
|
|
|
assert "not_yet_a: A" in example_file
|
2019-04-22 04:45:08 +00:00
|
|
|
assert "is_an_a" in example_file
|
|
|
|
assert "ClassVar" in example_file
|
|
|
|
|
|
|
|
assert "instance_var" in example_file
|
|
|
|
|
|
|
|
assert "global_a :A" in example_file
|
|
|
|
|
|
|
|
|
2020-01-10 01:16:59 +00:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
sys.version_info < (3, 8), reason="Positional only arguments need Python >=3.8"
|
|
|
|
)
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestPositionalOnlyArgumentsModule:
|
2020-01-10 01:16:59 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("py38positionalparams")
|
|
|
|
|
|
|
|
def test_integration(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "f_simple(a, b, /, c, d, *, e, f)" in example_file
|
|
|
|
|
|
|
|
assert (
|
|
|
|
"f_comment(a: int, b: int, /, c: Optional[int], d: Optional[int], *, e: float, f: float)"
|
|
|
|
in example_file
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
"f_annotation(a: int, b: int, /, c: Optional[int], d: Optional[int], *, e: float, f: float)"
|
|
|
|
in example_file
|
|
|
|
)
|
2020-05-15 11:22:19 +00:00
|
|
|
assert (
|
|
|
|
"f_arg_comment(a: int, b: int, /, c: Optional[int], d: Optional[int], *, e: float, f: float)"
|
|
|
|
in example_file
|
|
|
|
)
|
2020-01-10 01:16:59 +00:00
|
|
|
assert "f_no_cd(a: int, b: int, /, *, e: float, f: float)" in example_file
|
|
|
|
|
|
|
|
|
2018-12-14 01:52:06 +00:00
|
|
|
def test_napoleon_integration_loaded(builder):
|
|
|
|
confoverrides = {
|
2019-01-27 05:20:45 +00:00
|
|
|
"extensions": ["autoapi.extension", "sphinx.ext.autodoc", "sphinx.ext.napoleon"]
|
2018-12-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Parameters" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Return type" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Args" not in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestSimplePackage:
|
2019-01-27 05:20:45 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
2018-12-14 01:52:06 +00:00
|
|
|
def built(self, builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
builder("pypackageexample")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2018-12-18 11:27:43 +00:00
|
|
|
def test_integration_with_package(self):
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "example.foo" in example_file
|
|
|
|
assert "example.module_level_method(foo, bar)" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
example_foo_path = "_build/text/autoapi/example/foo/index.txt"
|
|
|
|
with io.open(example_foo_path, encoding="utf8") as example_foo_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_foo_file = example_foo_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "class example.foo.Foo" in example_foo_file
|
|
|
|
assert "method_okay(self, foo=None, bar=None)" in example_foo_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
index_path = "_build/text/index.txt"
|
|
|
|
with io.open(index_path, encoding="utf8") as index_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
index_file = index_handle.read()
|
|
|
|
|
2019-04-06 18:15:18 +00:00
|
|
|
assert "API Reference" in index_file
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "example.foo" in index_file
|
|
|
|
assert "Foo" in index_file
|
|
|
|
assert "module_level_method" in index_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
2019-02-05 05:21:32 +00:00
|
|
|
def test_simple_no_false_warnings(builder, caplog):
|
|
|
|
logger = sphinx.util.logging.getLogger("autoapi")
|
|
|
|
logger.logger.addHandler(caplog.handler)
|
|
|
|
builder("pypackageexample")
|
|
|
|
|
|
|
|
assert "Cannot resolve" not in caplog.text
|
|
|
|
|
|
|
|
|
2018-12-14 01:52:06 +00:00
|
|
|
def _test_class_content(builder, class_content):
|
2019-01-27 05:20:45 +00:00
|
|
|
confoverrides = {"autoapi_python_class_content": class_content}
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
if class_content == "init":
|
|
|
|
assert "Can we parse arguments" not in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
else:
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Can we parse arguments" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
if class_content not in ("both", "init"):
|
|
|
|
assert "Constructor docstring" not in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
else:
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "Constructor docstring" in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_class_class_content(builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
_test_class_content(builder, "class")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_both_class_content(builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
_test_class_content(builder, "both")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_init_class_content(builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
_test_class_content(builder, "init")
|
2018-12-14 01:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_hiding_private_members(builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
confoverrides = {"autoapi_options": ["members", "undoc-members", "special-members"]}
|
|
|
|
builder("pypackageexample", confoverrides=confoverrides)
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
example_file = example_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "private" not in example_file
|
2018-12-14 01:52:06 +00:00
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
private_path = "_build/text/autoapi/example/_private_module/index.txt"
|
|
|
|
with io.open(private_path, encoding="utf8") as private_handle:
|
2018-12-14 01:52:06 +00:00
|
|
|
private_file = private_handle.read()
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
assert "public_method" in private_file
|
2018-12-18 11:27:43 +00:00
|
|
|
|
|
|
|
|
2020-01-25 22:21:56 +00:00
|
|
|
def test_hiding_inheritance(builder):
|
|
|
|
confoverrides = {"autoapi_options": ["members", "undoc-members", "special-members"]}
|
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "Bases:" not in example_file
|
|
|
|
|
|
|
|
|
2020-05-17 00:36:52 +00:00
|
|
|
def test_hiding_imported_members(builder):
|
|
|
|
confoverrides = {"autoapi_options": ["members", "undoc-members"]}
|
|
|
|
builder("pypackagecomplex", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
subpackage_path = "_build/text/autoapi/complex/subpackage/index.txt"
|
|
|
|
with io.open(subpackage_path, encoding="utf8") as subpackage_handle:
|
|
|
|
subpackage_file = subpackage_handle.read()
|
|
|
|
|
|
|
|
assert "Part of a public resolution chain." not in subpackage_file
|
|
|
|
|
|
|
|
package_path = "_build/text/autoapi/complex/index.txt"
|
|
|
|
with io.open(package_path, encoding="utf8") as package_handle:
|
|
|
|
package_file = package_handle.read()
|
|
|
|
|
|
|
|
assert "Part of a public resolution chain." not in package_file
|
|
|
|
|
|
|
|
submodule_path = "_build/text/autoapi/complex/subpackage/submodule/index.txt"
|
|
|
|
with io.open(submodule_path, encoding="utf8") as submodule_handle:
|
|
|
|
submodule_file = submodule_handle.read()
|
|
|
|
|
|
|
|
assert "A private function made public by import." not in submodule_file
|
|
|
|
|
|
|
|
|
2020-01-26 01:30:59 +00:00
|
|
|
def test_inherited_members(builder):
|
|
|
|
confoverrides = {
|
|
|
|
"autoapi_options": ["members", "inherited-members", "undoc-members"]
|
|
|
|
}
|
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "class example.Bar" in example_file
|
|
|
|
i = example_file.index("class example.Bar")
|
|
|
|
assert "method_okay" in example_file[i:]
|
|
|
|
|
|
|
|
|
2020-01-25 22:21:56 +00:00
|
|
|
def test_skipping_members(builder):
|
2019-09-04 21:44:35 +00:00
|
|
|
builder("pyskipexample")
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "foo doc" not in example_file
|
|
|
|
assert "bar doc" not in example_file
|
|
|
|
assert "bar m doc" not in example_file
|
|
|
|
assert "baf doc" in example_file
|
|
|
|
assert "baf m doc" not in example_file
|
|
|
|
assert "baz doc" not in example_file
|
|
|
|
assert "not ignored" in example_file
|
|
|
|
|
|
|
|
|
2020-05-16 22:28:43 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"value,order",
|
|
|
|
[
|
2020-06-13 08:33:53 +00:00
|
|
|
("bysource", [".Foo", ".decorator_okay", ".Bar"]),
|
|
|
|
("alphabetical", [".Bar", ".Foo", ".decorator_okay"]),
|
|
|
|
("groupwise", [".Bar", ".Foo", ".decorator_okay"]),
|
2020-05-16 22:28:43 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_order_members(builder, value, order):
|
|
|
|
confoverrides = {"autoapi_member_order": value}
|
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
indexes = [example_file.index(name) for name in order]
|
|
|
|
assert indexes == sorted(indexes)
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class _CompareInstanceType:
|
2019-09-04 21:44:35 +00:00
|
|
|
def __init__(self, type_):
|
|
|
|
self.type = type_
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.type is type(other)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<expect type {}>".format(self.type.__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def test_skip_members_hook(builder):
|
|
|
|
emit_firstresult_patch = Mock(name="emit_firstresult_patch", return_value=False)
|
|
|
|
with patch("sphinx.application.Sphinx.emit_firstresult", emit_firstresult_patch):
|
|
|
|
builder("pyskipexample")
|
|
|
|
|
|
|
|
options = ["members", "undoc-members", "special-members"]
|
|
|
|
|
|
|
|
mock_calls = [
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"module",
|
|
|
|
"example",
|
|
|
|
_CompareInstanceType(PythonModule),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"function",
|
|
|
|
"example.foo",
|
|
|
|
_CompareInstanceType(PythonFunction),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"class",
|
|
|
|
"example.Bar",
|
|
|
|
_CompareInstanceType(PythonClass),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"class",
|
|
|
|
"example.Baf",
|
|
|
|
_CompareInstanceType(PythonClass),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"data",
|
|
|
|
"example.baz",
|
|
|
|
_CompareInstanceType(PythonData),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"data",
|
|
|
|
"example.anchor",
|
|
|
|
_CompareInstanceType(PythonData),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"method",
|
|
|
|
"example.Bar.m",
|
|
|
|
_CompareInstanceType(PythonMethod),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
call(
|
|
|
|
"autoapi-skip-member",
|
|
|
|
"method",
|
|
|
|
"example.Baf.m",
|
|
|
|
_CompareInstanceType(PythonMethod),
|
|
|
|
False,
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
for mock_call in mock_calls:
|
|
|
|
assert mock_call in emit_firstresult_patch.mock_calls
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestComplexPackage:
|
2019-01-27 05:20:45 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
2018-12-18 11:27:43 +00:00
|
|
|
def built(self, builder):
|
2019-01-27 05:20:45 +00:00
|
|
|
builder("pypackagecomplex")
|
2018-12-18 11:27:43 +00:00
|
|
|
|
|
|
|
def test_public_chain_resolves(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
submodule_path = "_build/text/autoapi/complex/subpackage/submodule/index.txt"
|
|
|
|
with io.open(submodule_path, encoding="utf8") as submodule_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
submodule_file = submodule_handle.read()
|
|
|
|
|
|
|
|
assert "Part of a public resolution chain." in submodule_file
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
subpackage_path = "_build/text/autoapi/complex/subpackage/index.txt"
|
|
|
|
with io.open(subpackage_path, encoding="utf8") as subpackage_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
subpackage_file = subpackage_handle.read()
|
|
|
|
|
|
|
|
assert "Part of a public resolution chain." in subpackage_file
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
package_path = "_build/text/autoapi/complex/index.txt"
|
|
|
|
with io.open(package_path, encoding="utf8") as package_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
package_file = package_handle.read()
|
|
|
|
|
|
|
|
assert "Part of a public resolution chain." in package_file
|
|
|
|
|
|
|
|
def test_private_made_public(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
submodule_path = "_build/text/autoapi/complex/subpackage/submodule/index.txt"
|
|
|
|
with io.open(submodule_path, encoding="utf8") as submodule_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
submodule_file = submodule_handle.read()
|
|
|
|
|
|
|
|
assert "A private function made public by import." in submodule_file
|
|
|
|
|
|
|
|
def test_multiple_import_locations(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
submodule_path = "_build/text/autoapi/complex/subpackage/submodule/index.txt"
|
|
|
|
with io.open(submodule_path, encoding="utf8") as submodule_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
submodule_file = submodule_handle.read()
|
|
|
|
|
|
|
|
assert "A public function imported in multiple places." in submodule_file
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
subpackage_path = "_build/text/autoapi/complex/subpackage/index.txt"
|
|
|
|
with io.open(subpackage_path, encoding="utf8") as subpackage_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
subpackage_file = subpackage_handle.read()
|
|
|
|
|
|
|
|
assert "A public function imported in multiple places." in subpackage_file
|
|
|
|
|
2019-01-27 05:20:45 +00:00
|
|
|
package_path = "_build/text/autoapi/complex/index.txt"
|
|
|
|
with io.open(package_path, encoding="utf8") as package_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
package_file = package_handle.read()
|
|
|
|
|
|
|
|
assert "A public function imported in multiple places." in package_file
|
|
|
|
|
|
|
|
def test_simple_wildcard_imports(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
wildcard_path = "_build/text/autoapi/complex/wildcard/index.txt"
|
|
|
|
with io.open(wildcard_path, encoding="utf8") as wildcard_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
wildcard_file = wildcard_handle.read()
|
|
|
|
|
|
|
|
assert "public_chain" in wildcard_file
|
|
|
|
assert "now_public_function" in wildcard_file
|
|
|
|
assert "public_multiple_imports" in wildcard_file
|
|
|
|
assert "module_level_method" in wildcard_file
|
|
|
|
|
|
|
|
def test_wildcard_chain(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
wildcard_path = "_build/text/autoapi/complex/wildchain/index.txt"
|
|
|
|
with io.open(wildcard_path, encoding="utf8") as wildcard_handle:
|
2018-12-18 11:27:43 +00:00
|
|
|
wildcard_file = wildcard_handle.read()
|
|
|
|
|
|
|
|
assert "public_chain" in wildcard_file
|
|
|
|
assert "module_level_method" in wildcard_file
|
2019-01-26 22:35:59 +00:00
|
|
|
|
|
|
|
def test_wildcard_all_imports(self):
|
2019-01-27 05:20:45 +00:00
|
|
|
wildcard_path = "_build/text/autoapi/complex/wildall/index.txt"
|
|
|
|
with io.open(wildcard_path, encoding="utf8") as wildcard_handle:
|
2019-01-26 22:35:59 +00:00
|
|
|
wildcard_file = wildcard_handle.read()
|
|
|
|
|
|
|
|
assert "not_all" not in wildcard_file
|
|
|
|
assert "NotAllClass" not in wildcard_file
|
|
|
|
assert "does_not_exist" not in wildcard_file
|
|
|
|
assert "SimpleClass" in wildcard_file
|
|
|
|
assert "simple_function" in wildcard_file
|
|
|
|
assert "public_chain" in wildcard_file
|
|
|
|
assert "module_level_method" in wildcard_file
|
2019-06-23 19:36:58 +00:00
|
|
|
|
|
|
|
def test_no_imports_in_module_with_all(self):
|
|
|
|
foo_path = "_build/text/autoapi/complex/foo/index.txt"
|
|
|
|
with io.open(foo_path, encoding="utf8") as foo_handle:
|
|
|
|
foo_file = foo_handle.read()
|
|
|
|
|
|
|
|
assert "module_level_method" not in foo_file
|
|
|
|
|
|
|
|
def test_all_overrides_import_in_module_with_all(self):
|
|
|
|
foo_path = "_build/text/autoapi/complex/foo/index.txt"
|
|
|
|
with io.open(foo_path, encoding="utf8") as foo_handle:
|
|
|
|
foo_file = foo_handle.read()
|
|
|
|
|
|
|
|
assert "PublicClass" in foo_file
|
2019-08-25 22:53:58 +00:00
|
|
|
|
|
|
|
def test_parses_unicode_file(self):
|
|
|
|
foo_path = "_build/text/autoapi/complex/unicode_data/index.txt"
|
|
|
|
with io.open(foo_path, encoding="utf8") as foo_handle:
|
|
|
|
foo_file = foo_handle.read()
|
|
|
|
|
|
|
|
assert "unicode_str" in foo_file
|
2019-10-15 08:41:09 +00:00
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestComplexPackageParallel:
|
2020-07-12 02:53:00 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("pypackagecomplex", parallel=2)
|
|
|
|
|
2021-06-28 00:09:09 +00:00
|
|
|
def test_success(self):
|
|
|
|
pass
|
|
|
|
|
2020-07-12 02:53:00 +00:00
|
|
|
|
2020-10-26 23:12:59 +00:00
|
|
|
def test_caching(builder):
|
|
|
|
mtimes = (0, 0)
|
|
|
|
|
|
|
|
def record_mtime():
|
|
|
|
nonlocal mtimes
|
|
|
|
mtime = 0
|
|
|
|
for root, _, files in os.walk("_build/text/autoapi"):
|
|
|
|
for name in files:
|
|
|
|
this_mtime = os.path.getmtime(os.path.join(root, name))
|
|
|
|
mtime = max(mtime, this_mtime)
|
|
|
|
|
|
|
|
mtimes = (*mtimes[1:], mtime)
|
|
|
|
|
|
|
|
builder("pypackagecomplex", confoverrides={"autoapi_keep_files": True})
|
|
|
|
record_mtime()
|
|
|
|
|
|
|
|
rebuild(confoverrides={"autoapi_keep_files": True})
|
|
|
|
record_mtime()
|
|
|
|
|
|
|
|
assert mtimes[1] == mtimes[0]
|
|
|
|
|
|
|
|
# Check that adding a file rebuilds the docs
|
|
|
|
extra_file = "complex/new.py"
|
|
|
|
with open(extra_file, "w") as out_f:
|
|
|
|
out_f.write("\n")
|
|
|
|
|
|
|
|
try:
|
|
|
|
rebuild(confoverrides={"autoapi_keep_files": True})
|
|
|
|
finally:
|
|
|
|
os.remove(extra_file)
|
|
|
|
|
|
|
|
record_mtime()
|
|
|
|
assert mtimes[1] != mtimes[0]
|
|
|
|
|
|
|
|
# Removing a file also rebuilds the docs
|
|
|
|
rebuild(confoverrides={"autoapi_keep_files": True})
|
|
|
|
record_mtime()
|
|
|
|
assert mtimes[1] != mtimes[0]
|
|
|
|
|
|
|
|
# Changing not keeping files always builds
|
|
|
|
rebuild()
|
|
|
|
record_mtime()
|
|
|
|
assert mtimes[1] != mtimes[0]
|
|
|
|
|
|
|
|
|
2021-04-04 02:01:27 +00:00
|
|
|
class TestImplicitNamespacePackage:
|
2019-10-15 08:41:09 +00:00
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("py3implicitnamespace")
|
|
|
|
|
|
|
|
def test_sibling_import_from_namespace(self):
|
|
|
|
example_path = "_build/text/autoapi/namespace/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "namespace.example.first_method" in example_file
|
|
|
|
|
|
|
|
def test_sub_sibling_import_from_namespace(self):
|
|
|
|
example_path = "_build/text/autoapi/namespace/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "namespace.example.second_sub_method" in example_file
|
2020-11-14 06:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_custom_jinja_filters(builder):
|
|
|
|
confoverrides = {
|
|
|
|
"autoapi_prepare_jinja_env": (
|
|
|
|
lambda jinja_env: jinja_env.filters.update(
|
|
|
|
{
|
|
|
|
"prepare_docstring": (
|
|
|
|
lambda docstring: "This is using custom filters."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
),
|
|
|
|
}
|
|
|
|
builder("pyexample", confoverrides=confoverrides)
|
|
|
|
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "This is using custom filters." in example_file
|
2021-02-15 14:07:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_string_module_attributes(builder):
|
|
|
|
"""Test toggle for multi-line string attribute values (GitHub #267)."""
|
|
|
|
keep_rst = {
|
|
|
|
"autoapi_keep_files": True,
|
|
|
|
"autoapi_root": "_build/autoapi", # Preserve RST files under _build for cleanup
|
|
|
|
}
|
|
|
|
builder("py3example", confoverrides=keep_rst)
|
|
|
|
|
|
|
|
example_path = os.path.join(keep_rst["autoapi_root"], "example", "index.rst")
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
code_snippet_contents = [
|
2021-06-28 00:09:09 +00:00
|
|
|
".. py:data:: code_snippet",
|
2021-02-15 14:07:02 +00:00
|
|
|
" :annotation: = Multiline-String",
|
|
|
|
"",
|
|
|
|
" .. raw:: html",
|
|
|
|
"",
|
|
|
|
" <details><summary>Show Value</summary>",
|
|
|
|
"",
|
|
|
|
" .. code-block:: text",
|
|
|
|
" :linenos:",
|
|
|
|
"",
|
|
|
|
" ", # <--- Line array monstrosity to preserve these leading spaces
|
|
|
|
" # -*- coding: utf-8 -*-",
|
|
|
|
" from __future__ import absolute_import, division, print_function, unicode_literals",
|
|
|
|
" # from future.builtins.disabled import *",
|
|
|
|
" # from builtins import *",
|
|
|
|
"",
|
|
|
|
""" print("chunky o'block")""",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
" .. raw:: html",
|
|
|
|
"",
|
|
|
|
" </details>",
|
|
|
|
]
|
|
|
|
assert "\n".join(code_snippet_contents) in example_file
|
2021-04-25 02:43:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestAutodocTypehintsPackage:
|
|
|
|
"""Test integrations with the autodoc.typehints extension."""
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope="class")
|
|
|
|
def built(self, builder):
|
|
|
|
builder("pyautodoc_typehints")
|
|
|
|
|
|
|
|
def test_renders_typehint(self):
|
|
|
|
example_path = "_build/text/autoapi/example/index.txt"
|
|
|
|
with io.open(example_path, encoding="utf8") as example_handle:
|
|
|
|
example_file = example_handle.read()
|
|
|
|
|
|
|
|
assert "(*int*)" in example_file
|
|
|
|
|
|
|
|
def test_renders_typehint_in_second_module(self):
|
|
|
|
example2_path = "_build/text/autoapi/example2/index.txt"
|
|
|
|
with io.open(example2_path, encoding="utf8") as example2_handle:
|
|
|
|
example2_file = example2_handle.read()
|
|
|
|
|
|
|
|
assert "(*int*)" in example2_file
|