Compare commits
11 Commits
5c163a09be
...
53de7fd42d
Author | SHA1 | Date |
---|---|---|
Ashley Whetter | 53de7fd42d | 2 months ago |
Ashley Whetter | f23b079e7d | 2 months ago |
Ashley Whetter | 3b037c7643 | 2 months ago |
Ashley Whetter | bc71226c3b | 2 months ago |
Ashley Whetter | 007077a7db | 2 months ago |
Ashley Whetter | a6558dcfc2 | 2 months ago |
Jorge Martinez | 2a603b8ac0 | 2 months ago |
Ashley Whetter | 93fb571a7e | 2 months ago |
Jorge Martinez Garrido | ecd47ea456 | 2 months ago |
George Zhang | 0d69974c19 | 2 months ago |
George Zhang | 34a96700ea | 2 months ago |
@ -1,3 +0,0 @@
|
||||
from .python import PythonSphinxMapper
|
||||
|
||||
__all__ = ("PythonSphinxMapper",)
|
@ -1,336 +0,0 @@
|
||||
import os
|
||||
import fnmatch
|
||||
from collections import OrderedDict, namedtuple
|
||||
import re
|
||||
|
||||
import anyascii
|
||||
from jinja2 import Environment, FileSystemLoader, TemplateNotFound
|
||||
import sphinx
|
||||
import sphinx.util
|
||||
from sphinx.util.console import colorize
|
||||
from sphinx.util.display import status_iterator
|
||||
from sphinx.util.osutil import ensuredir
|
||||
import sphinx.util.logging
|
||||
|
||||
from ..settings import API_ROOT, TEMPLATE_DIR
|
||||
|
||||
LOGGER = sphinx.util.logging.getLogger(__name__)
|
||||
|
||||
Path = namedtuple("Path", ["absolute", "relative"])
|
||||
|
||||
|
||||
class PythonMapperBase:
|
||||
"""Base object for JSON -> Python object mapping.
|
||||
|
||||
Subclasses of this object will handle their language specific JSON input,
|
||||
and map that onto this standard Python object.
|
||||
Subclasses may also include language-specific attributes on this object.
|
||||
|
||||
Arguments:
|
||||
|
||||
Args:
|
||||
obj: JSON object representing this object
|
||||
jinja_env: A template environment for rendering this object
|
||||
|
||||
Required attributes:
|
||||
|
||||
Attributes:
|
||||
id (str): A globally unique identifier for this object.
|
||||
Generally a fully qualified name, including namespace.
|
||||
name (str): A short "display friendly" name for this object.
|
||||
docstring (str): The documentation for this object
|
||||
imports (list): Imports in this object
|
||||
children (list): Children of this object
|
||||
parameters (list): Parameters to this object
|
||||
methods (list): Methods on this object
|
||||
|
||||
Optional attributes:
|
||||
|
||||
"""
|
||||
|
||||
language = "base"
|
||||
type = "base"
|
||||
# Create a page in the output for this object.
|
||||
top_level_object = False
|
||||
_RENDER_LOG_LEVEL = "VERBOSE"
|
||||
|
||||
def __init__(self, obj, jinja_env, app, options=None):
|
||||
self.app = app
|
||||
self.obj = obj
|
||||
self.options = options
|
||||
self.jinja_env = jinja_env
|
||||
self.url_root = os.path.join("/", API_ROOT)
|
||||
|
||||
self.name = None
|
||||
self.id = None
|
||||
|
||||
def __getstate__(self):
|
||||
"""Obtains serialisable data for pickling."""
|
||||
__dict__ = self.__dict__.copy()
|
||||
__dict__.update(app=None, jinja_env=None) # clear unpickable attributes
|
||||
return __dict__
|
||||
|
||||
def render(self, **kwargs):
|
||||
LOGGER.log(self._RENDER_LOG_LEVEL, "Rendering %s", self.id)
|
||||
|
||||
ctx = {}
|
||||
try:
|
||||
template = self.jinja_env.get_template(f"{self.language}/{self.type}.rst")
|
||||
except TemplateNotFound:
|
||||
template = self.jinja_env.get_template(f"base/{self.type}.rst")
|
||||
|
||||
ctx.update(**self.get_context_data())
|
||||
ctx.update(**kwargs)
|
||||
return template.render(**ctx)
|
||||
|
||||
@property
|
||||
def rendered(self):
|
||||
"""Shortcut to render an object in templates."""
|
||||
return self.render()
|
||||
|
||||
def get_context_data(self):
|
||||
return {
|
||||
"autoapi_options": self.app.config.autoapi_options,
|
||||
"include_summaries": self.app.config.autoapi_include_summaries,
|
||||
"obj": self,
|
||||
"sphinx_version": sphinx.version_info,
|
||||
}
|
||||
|
||||
def __lt__(self, other):
|
||||
"""Object sorting comparison"""
|
||||
if isinstance(other, PythonMapperBase):
|
||||
return self.id < other.id
|
||||
return super().__lt__(other)
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.__class__.__name__} {self.id}>"
|
||||
|
||||
@property
|
||||
def short_name(self):
|
||||
"""Shorten name property"""
|
||||
return self.name.split(".")[-1]
|
||||
|
||||
@property
|
||||
def pathname(self):
|
||||
"""Sluggified path for filenames
|
||||
|
||||
Slugs to a filename using the follow steps
|
||||
|
||||
* Decode unicode to approximate ascii
|
||||
* Remove existing hyphens
|
||||
* Substitute hyphens for non-word characters
|
||||
* Break up the string as paths
|
||||
"""
|
||||
slug = self.name
|
||||
slug = anyascii.anyascii(slug)
|
||||
slug = slug.replace("-", "")
|
||||
slug = re.sub(r"[^\w\.]+", "-", slug).strip("-")
|
||||
return os.path.join(*slug.split("."))
|
||||
|
||||
def include_dir(self, root):
|
||||
"""Return directory of file"""
|
||||
parts = [root]
|
||||
parts.extend(self.pathname.split(os.path.sep))
|
||||
return "/".join(parts)
|
||||
|
||||
@property
|
||||
def include_path(self):
|
||||
"""Return 'absolute' path without regarding OS path separator
|
||||
|
||||
This is used in ``toctree`` directives, as Sphinx always expects Unix
|
||||
path separators
|
||||
"""
|
||||
parts = [self.include_dir(root=self.url_root)]
|
||||
parts.append("index")
|
||||
return "/".join(parts)
|
||||
|
||||
@property
|
||||
def display(self):
|
||||
"""Whether to display this object or not.
|
||||
|
||||
:type: bool
|
||||
"""
|
||||
return True
|
||||
|
||||
@property
|
||||
def ref_type(self):
|
||||
return self.type
|
||||
|
||||
@property
|
||||
def ref_directive(self):
|
||||
return self.type
|
||||
|
||||
|
||||
class SphinxMapperBase:
|
||||
"""Base class for mapping `PythonMapperBase` objects to Sphinx.
|
||||
|
||||
Args:
|
||||
app: Sphinx application instance
|
||||
"""
|
||||
|
||||
def __init__(self, app, template_dir=None, url_root=None):
|
||||
self.app = app
|
||||
|
||||
template_paths = [TEMPLATE_DIR]
|
||||
|
||||
if template_dir:
|
||||
# Put at the front so it's loaded first
|
||||
template_paths.insert(0, template_dir)
|
||||
|
||||
self.jinja_env = Environment(
|
||||
loader=FileSystemLoader(template_paths),
|
||||
trim_blocks=True,
|
||||
lstrip_blocks=True,
|
||||
)
|
||||
|
||||
def _wrapped_prepare(value):
|
||||
return value
|
||||
|
||||
self.jinja_env.filters["prepare_docstring"] = _wrapped_prepare
|
||||
if self.app.config.autoapi_prepare_jinja_env:
|
||||
self.app.config.autoapi_prepare_jinja_env(self.jinja_env)
|
||||
|
||||
self.url_root = url_root
|
||||
|
||||
# Mapping of {filepath -> raw data}
|
||||
self.paths = OrderedDict()
|
||||
# Mapping of {object id -> Python Object}
|
||||
self.objects = OrderedDict()
|
||||
# Mapping of {object id -> Python Object}
|
||||
self.all_objects = OrderedDict()
|
||||
# Mapping of {namespace id -> Python Object}
|
||||
self.namespaces = OrderedDict()
|
||||
# Mapping of {namespace id -> Python Object}
|
||||
self.top_level_objects = OrderedDict()
|
||||
|
||||
def load(self, patterns, dirs, ignore=None):
|
||||
"""Load objects from the filesystem into the ``paths`` dictionary."""
|
||||
paths = list(self.find_files(patterns=patterns, dirs=dirs, ignore=ignore))
|
||||
for path in status_iterator(
|
||||
paths,
|
||||
colorize("bold", "[AutoAPI] Reading files... "),
|
||||
"darkgreen",
|
||||
len(paths),
|
||||
):
|
||||
data = self.read_file(path=path)
|
||||
if data:
|
||||
self.paths[path] = data
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def find_files(patterns, dirs, ignore):
|
||||
if not ignore:
|
||||
ignore = []
|
||||
|
||||
pattern_regexes = []
|
||||
for pattern in patterns:
|
||||
regex = re.compile(fnmatch.translate(pattern).replace(".*", "(.*)"))
|
||||
pattern_regexes.append((pattern, regex))
|
||||
|
||||
for _dir in dirs:
|
||||
for root, _, filenames in os.walk(_dir):
|
||||
seen = set()
|
||||
for pattern, pattern_re in pattern_regexes:
|
||||
for filename in fnmatch.filter(filenames, pattern):
|
||||
skip = False
|
||||
|
||||
match = re.match(pattern_re, filename)
|
||||
norm_name = match.groups()
|
||||
if norm_name in seen:
|
||||
continue
|
||||
|
||||
# Skip ignored files
|
||||
for ignore_pattern in ignore:
|
||||
if fnmatch.fnmatch(
|
||||
os.path.join(root, filename), ignore_pattern
|
||||
):
|
||||
LOGGER.info(
|
||||
colorize("bold", "[AutoAPI] ")
|
||||
+ colorize(
|
||||
"darkgreen", f"Ignoring {root}/{filename}"
|
||||
)
|
||||
)
|
||||
skip = True
|
||||
|
||||
if skip:
|
||||
continue
|
||||
|
||||
# Make sure the path is full
|
||||
if not os.path.isabs(filename):
|
||||
filename = os.path.join(root, filename)
|
||||
|
||||
yield filename
|
||||
seen.add(norm_name)
|
||||
|
||||
def read_file(self, path, **kwargs):
|
||||
"""Read file input into memory
|
||||
|
||||
Args:
|
||||
path: Path of file to read
|
||||
"""
|
||||
# TODO support JSON here
|
||||
# TODO sphinx way of reporting errors in logs?
|
||||
raise NotImplementedError
|
||||
|
||||
def add_object(self, obj):
|
||||
"""Add object to local and app environment storage
|
||||
|
||||
Args:
|
||||
obj: Instance of a AutoAPI object
|
||||
"""
|
||||
self.objects[obj.id] = obj
|
||||
self.all_objects[obj.id] = obj
|
||||
child_stack = list(obj.children)
|
||||
while child_stack:
|
||||
child = child_stack.pop()
|
||||
self.all_objects[child.id] = child
|
||||
child_stack.extend(getattr(child, "children", ()))
|
||||
|
||||
def map(self, options=None):
|
||||
"""Trigger find of serialized sources and build objects"""
|
||||
for _, data in status_iterator(
|
||||
self.paths.items(),
|
||||
colorize("bold", "[AutoAPI] ") + "Mapping Data... ",
|
||||
length=len(self.paths),
|
||||
stringify_func=(lambda x: x[0]),
|
||||
):
|
||||
for obj in self.create_class(data, options=options):
|
||||
self.add_object(obj)
|
||||
|
||||
def create_class(self, data, options=None, **kwargs):
|
||||
"""Create class object.
|
||||
|
||||
Args:
|
||||
data: Instance of a AutoAPI object
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def output_rst(self, root, source_suffix):
|
||||
for _, obj in status_iterator(
|
||||
self.objects.items(),
|
||||
colorize("bold", "[AutoAPI] ") + "Rendering Data... ",
|
||||
length=len(self.objects),
|
||||
verbosity=1,
|
||||
stringify_func=(lambda x: x[0]),
|
||||
):
|
||||
rst = obj.render()
|
||||
if not rst:
|
||||
continue
|
||||
|
||||
detail_dir = obj.include_dir(root=root)
|
||||
ensuredir(detail_dir)
|
||||
path = os.path.join(detail_dir, f"index{source_suffix}")
|
||||
with open(path, "wb+") as detail_file:
|
||||
detail_file.write(rst.encode("utf-8"))
|
||||
|
||||
if self.app.config.autoapi_add_toctree_entry:
|
||||
self._output_top_rst(root)
|
||||
|
||||
def _output_top_rst(self, root):
|
||||
# Render Top Index
|
||||
top_level_index = os.path.join(root, "index.rst")
|
||||
pages = self.objects.values()
|
||||
with open(top_level_index, "wb") as top_level_file:
|
||||
content = self.jinja_env.get_template("index.rst")
|
||||
top_level_file.write(content.render(pages=pages).encode("utf-8"))
|
@ -1,25 +0,0 @@
|
||||
from .mapper import PythonSphinxMapper
|
||||
from .objects import (
|
||||
PythonAttribute,
|
||||
PythonClass,
|
||||
PythonData,
|
||||
PythonException,
|
||||
PythonFunction,
|
||||
PythonMethod,
|
||||
PythonModule,
|
||||
PythonPackage,
|
||||
PythonProperty,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
"PythonAttribute",
|
||||
"PythonClass",
|
||||
"PythonData",
|
||||
"PythonException",
|
||||
"PythonFunction",
|
||||
"PythonMethod",
|
||||
"PythonModule",
|
||||
"PythonPackage",
|
||||
"PythonProperty",
|
||||
"PythonSphinxMapper",
|
||||
)
|
@ -1,7 +0,0 @@
|
||||
.. {{ obj.type }}:: {{ obj.name }}
|
||||
|
||||
{% if summary %}
|
||||
|
||||
{{ obj.summary }}
|
||||
|
||||
{% endif %}
|
@ -1,60 +1,104 @@
|
||||
{% if obj.display %}
|
||||
.. py:{{ obj.type }}:: {{ obj.short_name }}{% if obj.args %}({{ obj.args }}){% endif %}
|
||||
{% if is_own_page %}
|
||||
{{ 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,38 @@
|
||||
{% if obj.display %}
|
||||
.. py:{{ obj.type }}:: {{ obj.name }}
|
||||
{%- if obj.annotation is not none %}
|
||||
{% if is_own_page %}
|
||||
{{ 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.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 %}
|
||||
:value: {{ obj.value|truncate(100) }}
|
||||
{% 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 %}
|
||||
{{ 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 %}
|
||||
{{ 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 @@
|
||||
Fix emitting ignore event twice for methods.
|
@ -0,0 +1 @@
|
||||
Refactor mapper classes into their bases
|
@ -0,0 +1 @@
|
||||
Values are always rendered for TypeAlises and PEP-695 type aliases.
|
@ -0,0 +1 @@
|
||||
Objects can render to their own page
|
@ -0,0 +1 @@
|
||||
Render PEP-695 type aliases as TypeAlias assignments.
|
@ -0,0 +1 @@
|
||||
Preserve strings inside Literal type annotations
|
@ -0,0 +1 @@
|
||||
Stopped using xrefs in page titles
|
@ -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
|
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
templates_path = ["_templates"]
|
||||
source_suffix = ".rst"
|
||||
master_doc = "index"
|
||||
project = "pyexample"
|
||||
copyright = "2015, readthedocs"
|
||||
author = "readthedocs"
|
||||
version = "0.1"
|
||||
release = "0.1"
|
||||
language = "en"
|
||||
exclude_patterns = ["_build"]
|
||||
pygments_style = "sphinx"
|
||||
todo_include_todos = False
|
||||
html_theme = "alabaster"
|
||||
htmlhelp_basename = "pyexampledoc"
|
||||
extensions = ["sphinx.ext.intersphinx", "sphinx.ext.autodoc", "autoapi.extension"]
|
||||
intersphinx_mapping = {"python": ("https://docs.python.org/3.10", None)}
|
||||
autoapi_dirs = ["example"]
|
||||
autoapi_file_pattern = "*.py"
|
@ -0,0 +1,4 @@
|
||||
from typing import TypeAlias
|
||||
|
||||
MyTypeAliasA: TypeAlias = tuple[str, int]
|
||||
type MyTypeAliasB = tuple[str, int]
|
@ -0,0 +1,26 @@
|
||||
.. pyexample documentation master file, created by
|
||||
sphinx-quickstart on Fri May 29 13:34:37 2015.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to pyexample's documentation!
|
||||
=====================================
|
||||
|
||||
.. toctree::
|
||||
|
||||
autoapi/index
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
@ -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