From b674b52ce9764ddb6693f447686228eb1bb949bd Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Wed, 31 Jan 2024 20:47:35 -0800 Subject: [PATCH] fixup! WIP Better single page class output --- autoapi/templates/python/class.rst | 1 + tests/python/test_own_page_option.py | 89 +++++++++++++++++++++------- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/autoapi/templates/python/class.rst b/autoapi/templates/python/class.rst index 75965555..67ce4280 100644 --- a/autoapi/templates/python/class.rst +++ b/autoapi/templates/python/class.rst @@ -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 %} diff --git a/tests/python/test_own_page_option.py b/tests/python/test_own_page_option.py index d4ffe6e7..c2dc35ee 100644 --- a/tests/python/test_own_page_option.py +++ b/tests/python/test_own_page_option.py @@ -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: @@ -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) @@ -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: