Compare commits
6 Commits
9e19e4af60
...
5c163a09be
Author | SHA1 | Date |
---|---|---|
Ashley Whetter | 5c163a09be | 2 months ago |
Jorge Martinez | 8a608d0d11 | 2 months ago |
Ashley Whetter | b33cc1a073 | 2 months ago |
Jorge Martinez Garrido | faf26ed6cc | 2 months ago |
Ashley Whetter | bea6e14a89 | 2 months ago |
Ashley Whetter | 67c0b5f821 | 2 months ago |
@ -1,60 +1,104 @@
|
||||
{% if obj.display %}
|
||||
.. py:{{ obj.type }}:: {{ obj.short_name }}{% if obj.args %}({{ obj.args }}){% endif %}
|
||||
{% if is_own_page %}
|
||||
:class:`{{ obj.id }}`
|
||||
========={{ "=" * obj.id | length }}
|
||||
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
|
||||
{% endif %}
|
||||
{% set visible_children = obj.children|selectattr("display")|list %}
|
||||
{% set own_page_children = visible_children|selectattr("type", "in", own_page_types)|list %}
|
||||
{% if is_own_page and own_page_children %}
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
{% for child in own_page_children %}
|
||||
{{ child.include_path }}
|
||||
{% endfor %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}{% if obj.args %}({{ obj.args }}){% endif %}
|
||||
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
{{ " " * (obj.type | length) }} {{ obj.short_name }}{% if args %}({{ args }}){% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% if obj.bases %}
|
||||
{% if "show-inheritance" in autoapi_options %}
|
||||
{% if "show-inheritance" in autoapi_options %}
|
||||
|
||||
Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %}
|
||||
{% if "show-inheritance-diagram" in autoapi_options and obj.bases != ["object"] %}
|
||||
.. autoapi-inheritance-diagram:: {{ obj.obj["full_name"] }}
|
||||
:parts: 1
|
||||
{% if "private-members" in autoapi_options %}
|
||||
{% if "private-members" in autoapi_options %}
|
||||
:private-bases:
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if obj.docstring %}
|
||||
|
||||
{{ obj.docstring|indent(3) }}
|
||||
{% endif %}
|
||||
{% if "inherited-members" in autoapi_options %}
|
||||
{% set visible_classes = obj.classes|selectattr("display")|list %}
|
||||
{% else %}
|
||||
{% set visible_classes = obj.classes|rejectattr("inherited")|selectattr("display")|list %}
|
||||
{% endif %}
|
||||
{% for klass in visible_classes %}
|
||||
{{ klass.render()|indent(3) }}
|
||||
{% endfor %}
|
||||
{% if "inherited-members" in autoapi_options %}
|
||||
{% set visible_properties = obj.properties|selectattr("display")|list %}
|
||||
{% else %}
|
||||
{% set visible_properties = obj.properties|rejectattr("inherited")|selectattr("display")|list %}
|
||||
{% endif %}
|
||||
{% for property in visible_properties %}
|
||||
{{ property.render()|indent(3) }}
|
||||
{% endfor %}
|
||||
{% if "inherited-members" in autoapi_options %}
|
||||
{% set visible_attributes = obj.attributes|selectattr("display")|list %}
|
||||
{% else %}
|
||||
{% set visible_attributes = obj.attributes|rejectattr("inherited")|selectattr("display")|list %}
|
||||
{% endif %}
|
||||
{% for attribute in visible_attributes %}
|
||||
{{ attribute.render()|indent(3) }}
|
||||
{% for obj_item in visible_children %}
|
||||
{% if obj_item.type not in own_page_types %}
|
||||
|
||||
{{ obj_item.render()|indent(3) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if "inherited-members" in autoapi_options %}
|
||||
{% set visible_methods = obj.methods|selectattr("display")|list %}
|
||||
{% else %}
|
||||
{% set visible_methods = obj.methods|rejectattr("inherited")|selectattr("display")|list %}
|
||||
{% if is_own_page and own_page_children %}
|
||||
{% set visible_attributes = own_page_children|selectattr("type", "equalto", "attribute")|list %}
|
||||
{% if visible_attributes %}
|
||||
Attributes
|
||||
----------
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for attribute in visible_attributes %}
|
||||
{{ attribute.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% set visible_exceptions = own_page_children|selectattr("type", "equalto", "exception")|list %}
|
||||
{% if visible_exceptions %}
|
||||
Exceptions
|
||||
----------
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for exception in visible_exceptions %}
|
||||
{{ exception.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% set visible_classes = own_page_children|selectattr("type", "equalto", "class")|list %}
|
||||
{% if visible_classes %}
|
||||
Classes
|
||||
-------
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for klass in visible_classes %}
|
||||
{{ klass.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% set visible_methods = own_page_children|selectattr("type", "equalto", "method")|list %}
|
||||
{% if visible_methods %}
|
||||
Methods
|
||||
-------
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for method in visible_methods %}
|
||||
{{ method.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% for method in visible_methods %}
|
||||
{{ method.render()|indent(3) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
@ -1,37 +1,42 @@
|
||||
{% if obj.display %}
|
||||
.. py:{{ obj.type }}:: {{ obj.name }}
|
||||
{%- if obj.annotation is not none %}
|
||||
{% if is_own_page %}
|
||||
:py:{{ obj.type|truncate(4, True, "", 0) }}:`{{ obj.id }}`
|
||||
==========={{ "=" * obj.id | length }}
|
||||
|
||||
:type: {%- if obj.annotation %} {{ obj.annotation }}{%- endif %}
|
||||
{% endif %}
|
||||
.. py:{{ obj.type }}:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.name }}{% endif %}
|
||||
{% if obj.annotation is not none %}
|
||||
|
||||
{%- endif %}
|
||||
:type: {% if obj.annotation %} {{ obj.annotation }}{% endif %}
|
||||
{% endif %}
|
||||
{% if obj.value is not none %}
|
||||
|
||||
{%- if obj.value is not none %}
|
||||
{% if obj.value is string and obj.value.splitlines()|count > 1 %}
|
||||
:value: Multiline-String
|
||||
|
||||
:value: {% if obj.value is string and obj.value.splitlines()|count > 1 -%}
|
||||
Multiline-String
|
||||
.. raw:: html
|
||||
|
||||
.. raw:: html
|
||||
<details><summary>Show Value</summary>
|
||||
|
||||
<details><summary>Show Value</summary>
|
||||
.. code-block:: python
|
||||
|
||||
.. code-block:: python
|
||||
"""{{ obj.value|indent(width=6,blank=true) }}"""
|
||||
|
||||
"""{{ obj.value|indent(width=8,blank=true) }}"""
|
||||
.. raw:: html
|
||||
|
||||
.. raw:: html
|
||||
</details>
|
||||
|
||||
</details>
|
||||
|
||||
{%- else -%}
|
||||
{%- if obj.value is string -%}
|
||||
{{ "%r" % obj.value|string|truncate(100) }}
|
||||
{%- else -%}
|
||||
{{ obj.value|string|truncate(100) }}
|
||||
{%- endif -%}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{% else %}
|
||||
{% if obj.value is string %}
|
||||
:value: {{ "%r" % obj.value|string|truncate(100) }}
|
||||
{% else %}
|
||||
:value: {{ obj.value|string|truncate(100) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if obj.docstring %}
|
||||
|
||||
{{ obj.docstring|indent(3) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -1,15 +1,21 @@
|
||||
{% if obj.display %}
|
||||
.. py:function:: {{ obj.short_name }}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
|
||||
{% if is_own_page %}
|
||||
:py:func:`{{ obj.id }}`
|
||||
==========={{ "=" * obj.id | length }}
|
||||
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
{{ obj.short_name }}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
|
||||
{% endif %}
|
||||
.. py:function:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
|
||||
{% endfor %}
|
||||
{%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
|
||||
{% endfor %}
|
||||
{% for property in obj.properties %}
|
||||
|
||||
:{{ property }}:
|
||||
{% endfor %}
|
||||
|
||||
{% if obj.docstring %}
|
||||
|
||||
{{ obj.docstring|indent(3) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -1,19 +1,21 @@
|
||||
{%- if obj.display %}
|
||||
.. py:method:: {{ obj.short_name }}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
|
||||
{% if obj.display %}
|
||||
{% if is_own_page %}
|
||||
:py:meth:`{{ obj.id }}`
|
||||
==========={{ "=" * obj.id | length }}
|
||||
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
{{ obj.short_name }}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
|
||||
{% endif %}
|
||||
.. py:method:: {% if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ obj.args }}){% if obj.return_annotation is not none %} -> {{ obj.return_annotation }}{% endif %}
|
||||
{% for (args, return_annotation) in obj.overloads %}
|
||||
|
||||
{% endfor %}
|
||||
{% if obj.properties %}
|
||||
{%+ if is_own_page %}{{ obj.id }}{% else %}{{ obj.short_name }}{% endif %}({{ args }}){% if return_annotation is not none %} -> {{ return_annotation }}{% endif %}
|
||||
{% endfor %}
|
||||
{% for property in obj.properties %}
|
||||
|
||||
:{{ property }}:
|
||||
{% endfor %}
|
||||
|
||||
{% else %}
|
||||
|
||||
{% endif %}
|
||||
{% if obj.docstring %}
|
||||
|
||||
{{ obj.docstring|indent(3) }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -0,0 +1,68 @@
|
||||
import io
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
from unittest.mock import call
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import pytest
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def rebuild():
|
||||
def _rebuild(confdir=".", **kwargs):
|
||||
app = Sphinx(
|
||||
srcdir=".",
|
||||
confdir=confdir,
|
||||
outdir="_build/html",
|
||||
doctreedir="_build/.doctrees",
|
||||
buildername="html",
|
||||
pdb=True,
|
||||
**kwargs,
|
||||
)
|
||||
app.build()
|
||||
|
||||
return _rebuild
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def builder(rebuild):
|
||||
cwd = os.getcwd()
|
||||
|
||||
def build(test_dir, **kwargs):
|
||||
if kwargs.get("warningiserror"):
|
||||
# Add any warnings raised when using `Sphinx` more than once
|
||||
# in a Python session.
|
||||
confoverrides = kwargs.setdefault("confoverrides", {})
|
||||
confoverrides.setdefault("suppress_warnings", [])
|
||||
suppress = confoverrides["suppress_warnings"]
|
||||
suppress.append("app.add_node")
|
||||
suppress.append("app.add_directive")
|
||||
suppress.append("app.add_role")
|
||||
|
||||
os.chdir("tests/python/{0}".format(test_dir))
|
||||
rebuild(**kwargs)
|
||||
|
||||
yield build
|
||||
|
||||
try:
|
||||
shutil.rmtree("_build")
|
||||
if (pathlib.Path("autoapi") / "index.rst").exists():
|
||||
shutil.rmtree("autoapi")
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def parse():
|
||||
cache = {}
|
||||
|
||||
def parser(path):
|
||||
if path not in cache:
|
||||
with io.open(path, encoding="utf8") as file_handle:
|
||||
cache[path] = BeautifulSoup(file_handle, features="html.parser")
|
||||
|
||||
return cache[path]
|
||||
|
||||
yield parser
|
@ -1,2 +1,2 @@
|
||||
from ..wildcard import module_level_method
|
||||
from ..wildcard import module_level_function
|
||||
from ..wildcard import public_chain
|
||||
|
@ -1,8 +0,0 @@
|
||||
"""This is a docstring."""
|
||||
|
||||
from . import foo
|
||||
|
||||
|
||||
def module_level_method(foo, bar):
|
||||
"""A module level method"""
|
||||
pass
|
@ -0,0 +1,42 @@
|
||||
"""This is a docstring."""
|
||||
|
||||
from . import submodule
|
||||
from .subpackage.submodule import function as aliased_function
|
||||
from .subpackage.submodule import not_in_all_function
|
||||
|
||||
__all__ = (
|
||||
"aliased_function",
|
||||
"Class",
|
||||
"DATA",
|
||||
"function",
|
||||
"MyException",
|
||||
)
|
||||
|
||||
DATA = 42
|
||||
|
||||
|
||||
def function(foo, bar):
|
||||
"""A module level function"""
|
||||
|
||||
|
||||
class Class(object):
|
||||
"""This is a class."""
|
||||
|
||||
class_var = 42
|
||||
"""Class var docstring"""
|
||||
|
||||
class NestedClass(object):
|
||||
"""A nested class just to test things out"""
|
||||
|
||||
@classmethod
|
||||
def a_classmethod():
|
||||
"""A class method"""
|
||||
return True
|
||||
|
||||
def method_okay(self, foo=None, bar=None):
|
||||
"""This method should parse okay"""
|
||||
return True
|
||||
|
||||
|
||||
class MyException(Exception):
|
||||
"""This is an exception."""
|
@ -0,0 +1,13 @@
|
||||
"""This is a docstring."""
|
||||
|
||||
from .submodule import function as aliased_function
|
||||
from .submodule import not_in_all_function
|
||||
|
||||
__all__ = (
|
||||
"aliased_function",
|
||||
"function",
|
||||
)
|
||||
|
||||
|
||||
def function(foo, bar):
|
||||
"""A module level function"""
|
@ -0,0 +1,41 @@
|
||||
"""Example module
|
||||
|
||||
This is a description
|
||||
"""
|
||||
|
||||
DATA = 42
|
||||
|
||||
|
||||
def function(foo, bar):
|
||||
"""A module level function"""
|
||||
|
||||
|
||||
def _private_function():
|
||||
"""A function that shouldn't get rendered."""
|
||||
|
||||
|
||||
def not_in_all_function():
|
||||
"""A function that doesn't exist in __all__ when imported."""
|
||||
|
||||
|
||||
class Class(object):
|
||||
"""This is a class."""
|
||||
|
||||
class_var = 42
|
||||
"""Class var docstring"""
|
||||
|
||||
class NestedClass(object):
|
||||
"""A nested class just to test things out"""
|
||||
|
||||
@classmethod
|
||||
def a_classmethod():
|
||||
"""A class method"""
|
||||
return True
|
||||
|
||||
def method_okay(self, foo=None, bar=None):
|
||||
"""This method should parse okay"""
|
||||
return True
|
||||
|
||||
|
||||
class MyException(Exception):
|
||||
"""This is an exception."""
|
@ -0,0 +1,997 @@
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestModule:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def built(self, builder):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
warningiserror=True,
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": "module",
|
||||
"autoapi_options": [
|
||||
"members",
|
||||
"undoc-members",
|
||||
"show-inheritance",
|
||||
"imported-members",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
def test_package(self, parse):
|
||||
package_path = "_build/html/autoapi/package/index.html"
|
||||
package_file = parse(package_path)
|
||||
|
||||
docstring = package_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
subpackages = package_file.find(id="subpackages")
|
||||
assert subpackages
|
||||
assert subpackages.find("a", string="package.subpackage")
|
||||
submodules = package_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.submodule")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not package_file.find(id="attributes")
|
||||
assert not package_file.find(id="exceptions")
|
||||
assert not package_file.find(id="classes")
|
||||
assert not package_file.find(id="functions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = package_file.find(id="package-contents")
|
||||
assert contents.find(id="package.DATA")
|
||||
assert contents.find(id="package.MyException")
|
||||
assert contents.find(id="package.Class")
|
||||
assert contents.find(id="package.Class.class_var")
|
||||
assert contents.find(id="package.Class.NestedClass")
|
||||
assert contents.find(id="package.Class.method_okay")
|
||||
assert contents.find(id="package.Class.NestedClass")
|
||||
assert contents.find(id="package.Class.NestedClass.a_classmethod")
|
||||
assert contents.find(id="package.function")
|
||||
assert contents.find(id="package.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.not_in_all_function")
|
||||
|
||||
def test_subpackage(self, parse):
|
||||
subpackage_path = "_build/html/autoapi/package/subpackage/index.html"
|
||||
subpackage_file = parse(subpackage_path)
|
||||
|
||||
docstring = subpackage_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
assert not subpackage_file.find(id="subpackages")
|
||||
submodules = subpackage_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.subpackage.submodule")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not subpackage_file.find(id="attributes")
|
||||
assert not subpackage_file.find(id="exceptions")
|
||||
assert not subpackage_file.find(id="classes")
|
||||
assert not subpackage_file.find(id="functions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = subpackage_file.find(id="package-contents")
|
||||
assert contents.find(id="package.subpackage.function")
|
||||
assert contents.find(id="package.subpackage.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.subpackage.not_in_all_function")
|
||||
|
||||
def test_module(self, parse):
|
||||
submodule_path = "_build/html/autoapi/package/submodule/index.html"
|
||||
submodule_file = parse(submodule_path)
|
||||
|
||||
docstring = submodule_file.find("p")
|
||||
assert docstring.text == "Example module"
|
||||
|
||||
# There should be links to the children with their own page
|
||||
pass # there are no children with their own page
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not submodule_file.find(id="submodules")
|
||||
assert not submodule_file.find(id="subpackages")
|
||||
assert not submodule_file.find(id="attributes")
|
||||
assert not submodule_file.find(id="exceptions")
|
||||
assert not submodule_file.find(id="classes")
|
||||
assert not submodule_file.find(id="functions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = submodule_file.find(id="module-contents")
|
||||
assert contents.find(id="package.submodule.DATA")
|
||||
assert contents.find(id="package.submodule.MyException")
|
||||
assert contents.find(id="package.submodule.Class")
|
||||
assert contents.find(id="package.submodule.Class.class_var")
|
||||
assert contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert contents.find(id="package.submodule.Class.method_okay")
|
||||
assert contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert contents.find(id="package.submodule.Class.NestedClass.a_classmethod")
|
||||
assert contents.find(id="package.submodule.function")
|
||||
assert contents.find(id="package.submodule.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.submodule.not_in_all_function")
|
||||
|
||||
def test_rendered_only_expected_pages(self):
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
|
||||
assert sorted(dirs) == ["submodule", "subpackage"]
|
||||
assert files == ["index.html"]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/submodule"))
|
||||
assert not dirs
|
||||
assert files == ["index.html"]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
|
||||
assert dirs == ["submodule"]
|
||||
assert files == ["index.html"]
|
||||
|
||||
_, dirs, files = next(
|
||||
os.walk("_build/html/autoapi/package/subpackage/submodule")
|
||||
)
|
||||
assert not dirs
|
||||
assert files == ["index.html"]
|
||||
|
||||
def test_index(self, parse):
|
||||
index_path = "_build/html/autoapi/index.html"
|
||||
index_file = parse(index_path)
|
||||
|
||||
top_links = index_file.find_all(class_="toctree-l1")
|
||||
top_hrefs = sorted(link.a["href"] for link in top_links)
|
||||
assert top_hrefs == [
|
||||
"#",
|
||||
"package/index.html",
|
||||
]
|
||||
|
||||
|
||||
class TestClass:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def built(self, builder):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
warningiserror=True,
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": "class",
|
||||
"autoapi_options": [
|
||||
"members",
|
||||
"undoc-members",
|
||||
"show-inheritance",
|
||||
"imported-members",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
def test_package(self, parse):
|
||||
package_path = "_build/html/autoapi/package/index.html"
|
||||
package_file = parse(package_path)
|
||||
|
||||
docstring = package_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
subpackages = package_file.find(id="subpackages")
|
||||
assert subpackages
|
||||
assert subpackages.find("a", string="package.subpackage")
|
||||
submodules = package_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.submodule")
|
||||
exceptions = package_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.MyException")
|
||||
classes = package_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class")
|
||||
assert not classes.find("a", title="package.Class.NestedClass")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not package_file.find(id="attributes")
|
||||
assert not package_file.find(id="functions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = package_file.find(id="package-contents")
|
||||
assert contents.find(id="package.DATA")
|
||||
assert not contents.find(id="package.MyException")
|
||||
assert not contents.find(id="package.Class")
|
||||
assert not contents.find(id="package.Class.class_var")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.method_okay")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.NestedClass.a_classmethod")
|
||||
assert contents.find(id="package.function")
|
||||
assert contents.find(id="package.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.not_in_all_function")
|
||||
|
||||
def test_module(self, parse):
|
||||
submodule_path = "_build/html/autoapi/package/submodule/index.html"
|
||||
submodule_file = parse(submodule_path)
|
||||
|
||||
docstring = submodule_file.find("p")
|
||||
assert docstring.text == "Example module"
|
||||
|
||||
# There should be links to the children with their own page
|
||||
exceptions = submodule_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.submodule.MyException")
|
||||
classes = submodule_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.submodule.Class")
|
||||
assert not classes.find("a", title="package.submodule.Class.NestedClass")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not submodule_file.find(id="submodules")
|
||||
assert not submodule_file.find(id="subpackages")
|
||||
assert not submodule_file.find(id="attributes")
|
||||
assert not submodule_file.find(id="functions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = submodule_file.find(id="module-contents")
|
||||
assert contents.find(id="package.submodule.DATA")
|
||||
assert not contents.find(id="package.submodule.MyException")
|
||||
assert not contents.find(id="package.submodule.Class")
|
||||
assert not contents.find(id="package.submodule.Class.class_var")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.method_okay")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass.a_classmethod")
|
||||
assert contents.find(id="package.submodule.function")
|
||||
assert contents.find(id="package.submodule.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.submodule.not_in_all_function")
|
||||
|
||||
def test_class(self, parse):
|
||||
class_path = "_build/html/autoapi/package/Class.html"
|
||||
class_file = parse(class_path)
|
||||
|
||||
class_sig = class_file.find(id="package.Class")
|
||||
assert class_sig
|
||||
class_ = class_sig.parent
|
||||
docstring = class_.find_all("p")[1]
|
||||
assert docstring.text == "This is a class."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
classes = class_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class.NestedClass")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not class_file.find(id="attributes")
|
||||
assert not class_file.find(id="exceptions")
|
||||
assert not class_file.find(id="methods")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
assert class_.find(id="package.Class.class_var")
|
||||
assert class_.find(id="package.Class.method_okay")
|
||||
|
||||
nested_class_path = "_build/html/autoapi/package/Class.NestedClass.html"
|
||||
nested_class_file = parse(nested_class_path)
|
||||
|
||||
nested_class_sig = nested_class_file.find(id="package.Class.NestedClass")
|
||||
assert nested_class_sig
|
||||
nested_class = nested_class_sig.parent
|
||||
|
||||
# There should be links to the children with their own page
|
||||
pass # there are no children with their own page
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not class_file.find(id="attributes")
|
||||
assert not class_file.find(id="exceptions")
|
||||
assert not class_file.find(id="methods")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
assert nested_class.find(id="package.Class.NestedClass.a_classmethod")
|
||||
|
||||
def test_exception(self, parse):
|
||||
exception_path = "_build/html/autoapi/package/MyException.html"
|
||||
exception_file = parse(exception_path)
|
||||
|
||||
exception_sig = exception_file.find(id="package.MyException")
|
||||
assert exception_sig
|
||||
exception = exception_sig.parent
|
||||
docstring = exception.find_all("p")[1]
|
||||
assert docstring.text == "This is an exception."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
pass # there are no children with their own page
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not exception_file.find(id="attributes")
|
||||
assert not exception_file.find(id="exceptions")
|
||||
assert not exception_file.find(id="methods")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
pass # there are no children without their own page
|
||||
|
||||
def test_rendered_only_expected_pages(self):
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
|
||||
assert sorted(dirs) == ["submodule", "subpackage"]
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/submodule"))
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
|
||||
assert dirs == ["submodule"]
|
||||
assert files == ["index.html"]
|
||||
|
||||
_, dirs, files = next(
|
||||
os.walk("_build/html/autoapi/package/subpackage/submodule")
|
||||
)
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
def test_index(self, parse):
|
||||
index_path = "_build/html/autoapi/index.html"
|
||||
index_file = parse(index_path)
|
||||
|
||||
top_links = index_file.find_all(class_="toctree-l1")
|
||||
top_hrefs = sorted(link.a["href"] for link in top_links)
|
||||
assert top_hrefs == [
|
||||
"#",
|
||||
"package/index.html",
|
||||
]
|
||||
|
||||
|
||||
class TestFunction:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def built(self, builder):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
warningiserror=True,
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": "function",
|
||||
"autoapi_options": [
|
||||
"members",
|
||||
"undoc-members",
|
||||
"show-inheritance",
|
||||
"imported-members",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
def test_package(self, parse):
|
||||
package_path = "_build/html/autoapi/package/index.html"
|
||||
package_file = parse(package_path)
|
||||
|
||||
docstring = package_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
subpackages = package_file.find(id="subpackages")
|
||||
assert subpackages
|
||||
assert subpackages.find("a", string="package.subpackage")
|
||||
submodules = package_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.submodule")
|
||||
classes = package_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class")
|
||||
exceptions = package_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.MyException")
|
||||
functions = package_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.function")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not package_file.find(id="attributes")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = package_file.find(id="package-contents")
|
||||
assert contents.find(id="package.DATA")
|
||||
assert not contents.find(id="package.MyException")
|
||||
assert not contents.find(id="package.Class")
|
||||
assert not contents.find(id="package.Class.class_var")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.method_okay")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.NestedClass.a_classmethod")
|
||||
assert not contents.find(id="package.function")
|
||||
assert not contents.find(id="package.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.not_in_all_function")
|
||||
|
||||
def test_module(self, parse):
|
||||
submodule_path = "_build/html/autoapi/package/submodule/index.html"
|
||||
submodule_file = parse(submodule_path)
|
||||
|
||||
docstring = submodule_file.find("p")
|
||||
assert docstring.text == "Example module"
|
||||
|
||||
# There should be links to the children with their own page
|
||||
exceptions = submodule_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.submodule.MyException")
|
||||
classes = submodule_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.submodule.Class")
|
||||
assert not classes.find("a", title="package.submodule.Class.NestedClass")
|
||||
functions = submodule_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.submodule.function")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not submodule_file.find(id="submodules")
|
||||
assert not submodule_file.find(id="subpackages")
|
||||
assert not submodule_file.find(id="attributes")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = submodule_file.find(id="module-contents")
|
||||
assert contents.find(id="package.submodule.DATA")
|
||||
assert not contents.find(id="package.submodule.MyException")
|
||||
assert not contents.find(id="package.submodule.Class")
|
||||
assert not contents.find(id="package.submodule.Class.class_var")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.method_okay")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass.a_classmethod")
|
||||
assert not contents.find(id="package.submodule.function")
|
||||
assert not contents.find(id="package.submodule.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.submodule.not_in_all_function")
|
||||
|
||||
def test_class(self, parse):
|
||||
class_path = "_build/html/autoapi/package/Class.html"
|
||||
class_file = parse(class_path)
|
||||
|
||||
class_sig = class_file.find(id="package.Class")
|
||||
assert class_sig
|
||||
class_ = class_sig.parent
|
||||
docstring = class_.find_all("p")[1]
|
||||
assert docstring.text == "This is a class."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
classes = class_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class.NestedClass")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not class_file.find(id="attributes")
|
||||
assert not class_file.find(id="exceptions")
|
||||
assert not class_file.find(id="methods")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
assert class_.find(id="package.Class.class_var")
|
||||
assert class_.find(id="package.Class.method_okay")
|
||||
|
||||
def test_function(self, parse):
|
||||
function_path = "_build/html/autoapi/package/function.html"
|
||||
function_file = parse(function_path)
|
||||
|
||||
function_sig = function_file.find(id="package.function")
|
||||
assert function_sig
|
||||
|
||||
function_path = "_build/html/autoapi/package/submodule/function.html"
|
||||
function_file = parse(function_path)
|
||||
assert function_file.find(id="package.submodule.function")
|
||||
|
||||
def test_rendered_only_expected_pages(self):
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
|
||||
assert sorted(dirs) == ["submodule", "subpackage"]
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/submodule"))
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
|
||||
assert dirs == ["submodule"]
|
||||
assert sorted(files) == ["aliased_function.html", "function.html", "index.html"]
|
||||
|
||||
_, dirs, files = next(
|
||||
os.walk("_build/html/autoapi/package/subpackage/submodule")
|
||||
)
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"MyException.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
"not_in_all_function.html",
|
||||
]
|
||||
|
||||
def test_index(self, parse):
|
||||
index_path = "_build/html/autoapi/index.html"
|
||||
index_file = parse(index_path)
|
||||
|
||||
top_links = index_file.find_all(class_="toctree-l1")
|
||||
top_hrefs = sorted(link.a["href"] for link in top_links)
|
||||
assert top_hrefs == [
|
||||
"#",
|
||||
"package/index.html",
|
||||
]
|
||||
|
||||
|
||||
class TestMethod:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def built(self, builder):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
warningiserror=True,
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": "method",
|
||||
"autoapi_options": [
|
||||
"members",
|
||||
"undoc-members",
|
||||
"show-inheritance",
|
||||
"imported-members",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
def test_package(self, parse):
|
||||
package_path = "_build/html/autoapi/package/index.html"
|
||||
package_file = parse(package_path)
|
||||
|
||||
docstring = package_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
subpackages = package_file.find(id="subpackages")
|
||||
assert subpackages
|
||||
assert subpackages.find("a", string="package.subpackage")
|
||||
submodules = package_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.submodule")
|
||||
classes = package_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class")
|
||||
exceptions = package_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.MyException")
|
||||
functions = package_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.function")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not package_file.find(id="attributes")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = package_file.find(id="package-contents")
|
||||
assert contents.find(id="package.DATA")
|
||||
assert not contents.find(id="package.MyException")
|
||||
assert not contents.find(id="package.Class")
|
||||
assert not contents.find(id="package.Class.class_var")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.method_okay")
|
||||
assert not contents.find(id="package.Class.NestedClass")
|
||||
assert not contents.find(id="package.Class.NestedClass.a_classmethod")
|
||||
assert not contents.find(id="package.function")
|
||||
assert not contents.find(id="package.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.not_in_all_function")
|
||||
|
||||
def test_module(self, parse):
|
||||
submodule_path = "_build/html/autoapi/package/submodule/index.html"
|
||||
submodule_file = parse(submodule_path)
|
||||
|
||||
docstring = submodule_file.find("p")
|
||||
assert docstring.text == "Example module"
|
||||
|
||||
# There should be links to the children with their own page
|
||||
exceptions = submodule_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.submodule.MyException")
|
||||
classes = submodule_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.submodule.Class")
|
||||
assert not classes.find("a", title="package.submodule.Class.NestedClass")
|
||||
functions = submodule_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.submodule.function")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not submodule_file.find(id="submodules")
|
||||
assert not submodule_file.find(id="subpackages")
|
||||
assert not submodule_file.find(id="attributes")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
contents = submodule_file.find(id="module-contents")
|
||||
assert contents.find(id="package.submodule.DATA")
|
||||
assert not contents.find(id="package.submodule.MyException")
|
||||
assert not contents.find(id="package.submodule.Class")
|
||||
assert not contents.find(id="package.submodule.Class.class_var")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.method_okay")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass")
|
||||
assert not contents.find(id="package.submodule.Class.NestedClass.a_classmethod")
|
||||
assert not contents.find(id="package.submodule.function")
|
||||
assert not contents.find(id="package.submodule.aliased_function")
|
||||
|
||||
# Hidden children are never rendered.
|
||||
assert not contents.find(id="package.submodule.not_in_all_function")
|
||||
|
||||
def test_class(self, parse):
|
||||
class_path = "_build/html/autoapi/package/Class.html"
|
||||
class_file = parse(class_path)
|
||||
|
||||
class_sig = class_file.find(id="package.Class")
|
||||
assert class_sig
|
||||
class_ = class_sig.parent
|
||||
docstring = class_.find_all("p")[1]
|
||||
assert docstring.text == "This is a class."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
classes = class_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class.NestedClass")
|
||||
methods = class_file.find(id="methods")
|
||||
assert methods
|
||||
assert methods.find("a", title="package.Class.method_okay")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not class_file.find(id="attributes")
|
||||
assert not class_file.find(id="exceptions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
assert class_.find(id="package.Class.class_var")
|
||||
assert not class_.find(id="package.Class.method_okay")
|
||||
|
||||
def test_function(self, parse):
|
||||
function_path = "_build/html/autoapi/package/function.html"
|
||||
function_file = parse(function_path)
|
||||
|
||||
function_sig = function_file.find(id="package.function")
|
||||
assert function_sig
|
||||
|
||||
function_path = "_build/html/autoapi/package/submodule/function.html"
|
||||
function_file = parse(function_path)
|
||||
assert function_file.find(id="package.submodule.function")
|
||||
|
||||
def test_method(self, parse):
|
||||
method_path = "_build/html/autoapi/package/Class.method_okay.html"
|
||||
method_file = parse(method_path)
|
||||
|
||||
method_sig = method_file.find(id="package.Class.method_okay")
|
||||
assert method_sig
|
||||
|
||||
method_path = "_build/html/autoapi/package/submodule/Class.method_okay.html"
|
||||
method_file = parse(method_path)
|
||||
assert method_file.find(id="package.submodule.Class.method_okay")
|
||||
|
||||
def test_rendered_only_expected_pages(self):
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
|
||||
assert sorted(dirs) == ["submodule", "subpackage"]
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"Class.method_okay.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/submodule"))
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"Class.method_google_docs.html",
|
||||
"Class.method_multiline.html",
|
||||
"Class.method_okay.html",
|
||||
"Class.method_sphinx_docs.html",
|
||||
"Class.method_tricky.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
|
||||
assert dirs == ["submodule"]
|
||||
assert sorted(files) == ["aliased_function.html", "function.html", "index.html"]
|
||||
|
||||
_, dirs, files = next(
|
||||
os.walk("_build/html/autoapi/package/subpackage/submodule")
|
||||
)
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.html",
|
||||
"Class.method_okay.html",
|
||||
"MyException.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
"not_in_all_function.html",
|
||||
]
|
||||
|
||||
def test_index(self, parse):
|
||||
index_path = "_build/html/autoapi/index.html"
|
||||
index_file = parse(index_path)
|
||||
|
||||
top_links = index_file.find_all(class_="toctree-l1")
|
||||
top_hrefs = sorted(link.a["href"] for link in top_links)
|
||||
assert top_hrefs == [
|
||||
"#",
|
||||
"package/index.html",
|
||||
]
|
||||
|
||||
|
||||
class TestAttribute:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def built(self, builder):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
warningiserror=True,
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": "attribute",
|
||||
"autoapi_options": [
|
||||
"members",
|
||||
"undoc-members",
|
||||
"show-inheritance",
|
||||
"imported-members",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
# TODO: Include a test for a property
|
||||
def test_package(self, parse):
|
||||
package_path = "_build/html/autoapi/package/index.html"
|
||||
package_file = parse(package_path)
|
||||
|
||||
docstring = package_file.find("p")
|
||||
assert docstring.text == "This is a docstring."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
subpackages = package_file.find(id="subpackages")
|
||||
assert subpackages
|
||||
assert subpackages.find("a", string="package.subpackage")
|
||||
submodules = package_file.find(id="submodules")
|
||||
assert submodules
|
||||
assert submodules.find("a", string="package.submodule")
|
||||
classes = package_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class")
|
||||
exceptions = package_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.MyException")
|
||||
functions = package_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.function")
|
||||
attributes = package_file.find(id="attributes")
|
||||
assert attributes
|
||||
assert attributes.find("a", title="package.DATA")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
pass # there are no children without their own page
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
# Hidden children are never rendered.
|
||||
assert not package_file.find(id="package-contents")
|
||||
|
||||
def test_module(self, parse):
|
||||
submodule_path = "_build/html/autoapi/package/submodule/index.html"
|
||||
submodule_file = parse(submodule_path)
|
||||
|
||||
docstring = submodule_file.find("p")
|
||||
assert docstring.text == "Example module"
|
||||
|
||||
# There should be links to the children with their own page
|
||||
exceptions = submodule_file.find(id="exceptions")
|
||||
assert exceptions
|
||||
assert exceptions.find("a", title="package.submodule.MyException")
|
||||
classes = submodule_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.submodule.Class")
|
||||
assert not classes.find("a", title="package.submodule.Class.NestedClass")
|
||||
functions = submodule_file.find(id="functions")
|
||||
assert functions
|
||||
assert functions.find("a", title="package.submodule.function")
|
||||
attributes = submodule_file.find(id="attributes")
|
||||
assert attributes
|
||||
assert attributes.find("a", title="package.submodule.DATA")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not submodule_file.find(id="submodules")
|
||||
assert not submodule_file.find(id="subpackages")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
# Hidden children are never rendered.
|
||||
assert not submodule_file.find(id="module-contents")
|
||||
|
||||
def test_class(self, parse):
|
||||
class_path = "_build/html/autoapi/package/Class.html"
|
||||
class_file = parse(class_path)
|
||||
|
||||
class_sig = class_file.find(id="package.Class")
|
||||
assert class_sig
|
||||
class_ = class_sig.parent
|
||||
docstring = class_.find_all("p")[1]
|
||||
assert docstring.text == "This is a class."
|
||||
|
||||
# There should be links to the children with their own page
|
||||
classes = class_file.find(id="classes")
|
||||
assert classes
|
||||
assert classes.find("a", title="package.Class.NestedClass")
|
||||
methods = class_file.find(id="methods")
|
||||
assert methods
|
||||
assert methods.find("a", title="package.Class.method_okay")
|
||||
attributes = class_file.find(id="attributes")
|
||||
assert attributes
|
||||
assert attributes.find("a", title="package.Class.class_var")
|
||||
|
||||
# There should not be links to the children without their own page
|
||||
assert not class_file.find(id="exceptions")
|
||||
|
||||
# Children without their own page should be rendered on this page,
|
||||
# and children with their own page should not be rendered on this page.
|
||||
assert not class_.find(id="package.Class.class_var")
|
||||
assert not class_.find(id="package.Class.method_okay")
|
||||
|
||||
def test_function(self, parse):
|
||||
function_path = "_build/html/autoapi/package/function.html"
|
||||
function_file = parse(function_path)
|
||||
|
||||
function_sig = function_file.find(id="package.function")
|
||||
assert function_sig
|
||||
|
||||
function_path = "_build/html/autoapi/package/submodule/function.html"
|
||||
function_file = parse(function_path)
|
||||
assert function_file.find(id="package.submodule.function")
|
||||
|
||||
def test_method(self, parse):
|
||||
method_path = "_build/html/autoapi/package/Class.method_okay.html"
|
||||
method_file = parse(method_path)
|
||||
|
||||
method_sig = method_file.find(id="package.Class.method_okay")
|
||||
assert method_sig
|
||||
|
||||
method_path = "_build/html/autoapi/package/submodule/Class.method_okay.html"
|
||||
method_file = parse(method_path)
|
||||
assert method_file.find(id="package.submodule.Class.method_okay")
|
||||
|
||||
def test_data(self, parse):
|
||||
data_path = "_build/html/autoapi/package/DATA.html"
|
||||
data_file = parse(data_path)
|
||||
|
||||
data_sig = data_file.find(id="package.DATA")
|
||||
assert data_sig
|
||||
|
||||
def test_attribute(self, parse):
|
||||
attribute_path = "_build/html/autoapi/package/Class.class_var.html"
|
||||
attribute_file = parse(attribute_path)
|
||||
|
||||
attribute_sig = attribute_file.find(id="package.Class.class_var")
|
||||
assert attribute_sig
|
||||
|
||||
def test_rendered_only_expected_pages(self):
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
|
||||
assert sorted(dirs) == ["submodule", "subpackage"]
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.class_var.html",
|
||||
"Class.html",
|
||||
"Class.method_okay.html",
|
||||
"DATA.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/submodule"))
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.class_var.html",
|
||||
"Class.html",
|
||||
"Class.method_google_docs.html",
|
||||
"Class.method_multiline.html",
|
||||
"Class.method_okay.html",
|
||||
"Class.method_sphinx_docs.html",
|
||||
"Class.method_tricky.html",
|
||||
"DATA.html",
|
||||
"MyException.html",
|
||||
"aliased_function.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
]
|
||||
|
||||
_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
|
||||
assert dirs == ["submodule"]
|
||||
assert sorted(files) == ["aliased_function.html", "function.html", "index.html"]
|
||||
|
||||
_, dirs, files = next(
|
||||
os.walk("_build/html/autoapi/package/subpackage/submodule")
|
||||
)
|
||||
assert not dirs
|
||||
assert sorted(files) == [
|
||||
"Class.NestedClass.a_classmethod.html",
|
||||
"Class.NestedClass.html",
|
||||
"Class.class_var.html",
|
||||
"Class.html",
|
||||
"Class.method_okay.html",
|
||||
"DATA.html",
|
||||
"MyException.html",
|
||||
"function.html",
|
||||
"index.html",
|
||||
"not_in_all_function.html",
|
||||
]
|
||||
|
||||
def test_index(self, parse):
|
||||
index_path = "_build/html/autoapi/index.html"
|
||||
index_file = parse(index_path)
|
||||
|
||||
top_links = index_file.find_all(class_="toctree-l1")
|
||||
top_hrefs = sorted(link.a["href"] for link in top_links)
|
||||
assert top_hrefs == [
|
||||
"#",
|
||||
"package/index.html",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value", ["package", "exception", "property", "data", "not_a_value"]
|
||||
)
|
||||
def test_invalid_values(builder, value):
|
||||
"""Test failure when autoapi_own_page_level is invalid."""
|
||||
with pytest.raises(ValueError):
|
||||
builder(
|
||||
"pypackageexample",
|
||||
confoverrides={
|
||||
"autoapi_own_page_level": value,
|
||||
},
|
||||
)
|
Loading…
Reference in New Issue