Skip to content

Commit

Permalink
Merge pull request #854 from samjwu/tests
Browse files Browse the repository at this point in the history
Update configurations for site tests
  • Loading branch information
samjwu authored Jul 25, 2024
2 parents e959e59 + 6de4966 commit 90044ea
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/rocm_docs/doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from sphinx.application import Sphinx
from sphinx.config import Config
from sphinx.errors import ConfigError, ExtensionError
from sphinx.util import logging, progress_message
from sphinx.util import logging
from sphinx.util.display import progress_message
from sphinx.util.osutil import copyfile

from rocm_docs import util
Expand Down
6 changes: 3 additions & 3 deletions tests/sites/doxygen/extension/conf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
html_theme = "rocm_docs_theme"
extensions = ["rocm_docs", "rocm_docs.doxygen", "sphinxcontrib.doxylink"]
html_theme = "rocm_docs_theme"

external_projects_current_project = "a"

doxygen_project = {
"name": "ROCm Docs Core Test Project - Extension",
"path": "doxygen/xml",
}
doxysphinx_enabled = True

external_projects_current_project = "a"
2 changes: 1 addition & 1 deletion tests/sites/pass/minimal/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
html_theme = "rocm_docs_theme"
extensions = ["rocm_docs"]
html_theme = "rocm_docs_theme"

external_projects_current_project = "a"
2 changes: 1 addition & 1 deletion tests/sites/templates/minimal/.sphinx/_toc.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ entries:
- file: a.md
- title: External Project A
url: ${project:a}
- title: Externale Project B
- title: External Project B
url: ${project:b}
1 change: 1 addition & 0 deletions tests/sites/templates/standard/a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# A subdocument
1 change: 1 addition & 0 deletions tests/sites/templates/standard/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# rocm-docs core test site
7 changes: 7 additions & 0 deletions tests/sites/templates/standard/sphinx/_toc.yml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root: index.md
entries:
- file: a.md
- title: External Project A
url: ${project:a}
- title: External Project B
url: ${project:b}
16 changes: 16 additions & 0 deletions tests/sites/theme_flavors/rocm-blogs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extensions = ["rocm_docs"]
html_theme = "rocm_docs_theme"
html_theme_options = {"flavor": "rocm-blogs"}

external_toc_path = "./sphinx/_toc.yml"

external_projects_current_project = "a"

version = "1.0.0"
release = "1.0.0"
html_title = f"ROCm Docs Core Theme Test Project - ROCm Blogs Flavor"
project = "ROCm Docs Core"
author = "Advanced Micro Devices, Inc."
copyright = (
"Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved."
)
16 changes: 16 additions & 0 deletions tests/sites/theme_flavors/rocm-docs-home/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extensions = ["rocm_docs"]
html_theme = "rocm_docs_theme"
html_theme_options = {"flavor": "rocm-docs-home"}

external_toc_path = "./sphinx/_toc.yml"

external_projects_current_project = "a"

version = "1.0.0"
release = "1.0.0"
html_title = f"ROCm Docs Core Theme Test Project - ROCm Docs Home Flavor"
project = "ROCm Docs Core"
author = "Advanced Micro Devices, Inc."
copyright = (
"Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved."
)
16 changes: 16 additions & 0 deletions tests/sites/theme_flavors/rocm/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extensions = ["rocm_docs"]
html_theme = "rocm_docs_theme"
html_theme_options = {"flavor": "rocm"}

external_toc_path = "./sphinx/_toc.yml"

external_projects_current_project = "a"

version = "1.0.0"
release = "1.0.0"
html_title = f"ROCm Docs Core Theme Test Project - ROCm Flavor"
project = "ROCm Docs Core"
author = "Advanced Micro Devices, Inc."
copyright = (
"Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved."
)
32 changes: 19 additions & 13 deletions tests/sphinx_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

from __future__ import annotations

from typing import Any

import functools
import shutil
from collections.abc import Callable, Iterator
from pathlib import Path

import pytest
from sphinx.testing.path import path as sphinx_test_path
from sphinx.testing.util import SphinxTestApp
from sphinx.application import Sphinx

from .log_fixtures import ExpectLogFixture

Expand All @@ -25,27 +22,36 @@ def with_no_git_repo(
monkeypatch.setenv("ROCM_DOCS_REMOTE_DETAILS", ",")

with expect_log(
"sphinx.rocm_docs.theme",
"WARNING",
"Not in a Git Directory, disabling repository buttons",
"git.exc.InvalidGitRepositoryError",
"ERROR",
"test_external_projects",
) as validator:
yield validator


SITES_BASEFOLDER = Path(__file__).parent / "sites"


def build_sphinx(
srcdir: Path, outdir: Path, confdir: Path | None = None
) -> None:
confdir = confdir or srcdir
doctreedir = outdir / ".doctrees"
buildername = "html"
app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername)
app.build()


@pytest.fixture()
def build_factory(
request: pytest.FixtureRequest,
make_app: Callable[..., SphinxTestApp],
tmp_path: Path,
with_no_git_repo: ExpectLogFixture.Validator, # noqa: ARG001,
) -> Callable[..., SphinxTestApp]:
"""A factory to make Sphinx test applications"""
) -> Callable[..., tuple[Path, Path]]:
"""A factory to prepare Sphinx source and output directories"""

def make(src_folder: Path, /, **kwargs: dict[Any, Any]) -> SphinxTestApp:
def make(src_folder: Path, /) -> tuple[Path, Path]:
srcdir = tmp_path.joinpath(src_folder)
outdir = tmp_path.joinpath(f"{src_folder}_build")
srcdir.parent.mkdir(parents=True, exist_ok=True)

mark = request.node.get_closest_marker("template_folder")
Expand All @@ -56,7 +62,7 @@ def make(src_folder: Path, /, **kwargs: dict[Any, Any]) -> SphinxTestApp:
shutil.copytree(
SITES_BASEFOLDER / src_folder, srcdir, dirs_exist_ok=True
)
return make_app(srcdir=sphinx_test_path(srcdir), **kwargs)
return srcdir, outdir

if hasattr(request, "param"):
return functools.partial(make, request.param)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_update_doxylink_settings_skipped(
config_spec.append("doxylink")

config = unittest.mock.NonCallableMock(config_spec)
config.doxygen_html = "doxgen/html" if has_doxygen_html else None
config.doxygen_html = "doxygen/html" if has_doxygen_html else None
config.overrides = []
config._raw_config = []
expected: dict[str, tuple[str, str]]
Expand Down
Empty file removed tests/test_sites.py
Empty file.

0 comments on commit 90044ea

Please sign in to comment.