Skip to content

Commit

Permalink
fixup! WIP Better single page class output
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter committed Feb 1, 2024
1 parent c5eaed4 commit b674b52
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions autoapi/templates/python/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{% endfor %}
{% if obj.bases %}
{% if "show-inheritance" in autoapi_options %}

Bases: {% for base in obj.bases %}{{ base|link_objs }}{% if not loop.last %}, {% endif %}{% endfor %}
{% endif %}

Expand Down
89 changes: 67 additions & 22 deletions tests/python/test_own_page_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,68 @@ def built(self, builder):
confoverrides={"autoapi_own_page_level": "module"},
)

def test_module(self, parse):
def test_package(self, parse):
package_path = "_build/html/autoapi/package/index.html"
package_file = parse(package_path)

# TODO: Look for expected contents
docstring = package_file.find("p")
assert docstring.text == "This is a docstring."

#subpackage_path = "_build/html/autoapi/package/subpackage/index.html"
#subpackage_file = parse(subpackage_path)
# There should be links to the submodules and subpackages
assert package_file.find("a", title="package.submodule")
assert package_file.find("a", title="package.subpackage")

# TODO: Look for expected contents
contents = package_file.find(id="package-contents")
assert contents.find(id="package.function")

#submodule_path = "_build/html/autoapi/package/subpackage/submodule/index.html"
#submodule_file = parse(submodule_path)
def test_subpackage(self, parse):
subpackage_path = "_build/html/autoapi/package/subpackage/index.html"
subpackage_file = parse(subpackage_path)

# TODO: Look for expected contents
docstring = subpackage_file.find("p")
assert docstring.text == "This is a docstring."

assert not os.path.exists("_build/html/autoapi/package/subpackage/function.html")
# TODO: or listdir only contains index.html
assert not os.path.exists("_build/html/autoapi/package/subpackage/submodule/DATA.html")
assert not os.path.exists("_build/html/autoapi/package/subpackage/submodule/Class.html")
# There should be links to the submodules and subpackages
assert subpackage_file.find("a", title="subpackage.submodule")

# TODO: or listdir only contains index.html
assert not os.path.exists("_build/html/autoapi/package/submodule/DATA.html")
assert not os.path.exists("_build/html/autoapi/package/submodule/Class.html")
contents = subpackage_file.find(id="package-contents")
assert contents.find(id="package.subpackage.function")

def test_submodule(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"

contents = submodule_file.find(id="module-contents")
assert contents.find(id="package.submodule.DATA")
assert contents.find(id="package.submodule.Class")
assert contents.find(id="package.submodule.Class.NestedClass")

submodule_path = "_build/html/autoapi/package/subpackage/submodule/index.html"
submodule_file = parse(submodule_path)

docstring = submodule_file.find("p")
assert docstring.text == "Example module"

contents = submodule_file.find(id="module-contents")
assert contents.find(id="package.subpackage.submodule.DATA")
assert contents.find(id="package.subpackage.submodule.Class")
assert contents.find(id="package.subpackage.submodule.Class.NestedClass")

def test_rendered_only_expected_pages(self):
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
assert dirs == ["subpackage"]
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"]


class TestClass:
Expand All @@ -54,14 +92,11 @@ def built(self, builder):

# TODO: Include a test for an exception
def test_class(self, parse):
#submodule_path = "_build/html/autoapi/package/subpackage/submodule/index.html"
#submodule_file = parse(submodule_path)
submodule_path = "_build/html/autoapi/package/subpackage/submodule/index.html"
submodule_file = parse(submodule_path)

# TODO: Look for expected contents

assert not os.path.exists("_build/html/autoapi/package/subpackage/function.html")
assert not os.path.exists("_build/html/autoapi/package/subpackage/submodule/DATA.html")

#class_path = "_build/html/autoapi/package/subpackage/submodule/Class.html"
#class_file = parse(class_path)

Expand All @@ -87,8 +122,18 @@ def test_class(self, parse):

# TODO: Look for expected contents

# TODO: and listdir only .startswith("Class") is Class.NestedClass.html
assert not os.path.exists("_build/html/autoapi/package/submodule/DATA.html")
def test_rendered_only_expected_pages(self):
_, dirs, files = next(os.walk("_build/html/autoapi/package"))
assert dirs == ["subpackage"]
assert files == ["index.html"]

_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage"))
assert dirs == ["submodule"]
assert files == ["Class.html", "index.html"]

_, dirs, files = next(os.walk("_build/html/autoapi/package/subpackage/submodule"))
assert not dirs
assert files == ["Class.html", "index.html"]


class TestFunction:
Expand Down

0 comments on commit b674b52

Please sign in to comment.