diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a24091..d3eeb3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,6 +82,7 @@ jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: python-version: - "3.10" diff --git a/src/dvsim/templates/render.py b/src/dvsim/templates/render.py index 5e5d02a..20de56b 100644 --- a/src/dvsim/templates/render.py +++ b/src/dvsim/templates/render.py @@ -10,6 +10,7 @@ from collections.abc import Mapping from importlib import resources +from pathlib import Path from jinja2 import Environment, PackageLoader, select_autoescape @@ -28,9 +29,11 @@ def render_static(path: str) -> str: string containing the static file content """ + full_path = Path("dvsim/templates/static") / path + return resources.read_text( - "dvsim", - f"templates/static/{path}", + ".".join(full_path.parts[:-1]), # Module path + full_path.name, ) diff --git a/tests/templates/__init__.py b/tests/templates/__init__.py new file mode 100644 index 0000000..c7008e3 --- /dev/null +++ b/tests/templates/__init__.py @@ -0,0 +1,5 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +"""DVSim templates tests.""" diff --git a/tests/templates/test_render.py b/tests/templates/test_render.py new file mode 100644 index 0000000..aefd6f8 --- /dev/null +++ b/tests/templates/test_render.py @@ -0,0 +1,26 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +"""Test template renderer.""" + +import pytest +from hamcrest import assert_that, empty, is_not + +from dvsim.templates.render import render_static + + +@pytest.mark.parametrize( + "static_content_path", + [ + "css/style.css", + "css/bootstrap.min.css", + "js/bootstrap.bundle.min.js", + "js/htmx.min.js", + ], +) +def test_render_static(static_content_path: str) -> None: + """Test that static files are able to be rendered.""" + text = render_static(path=static_content_path) + + assert_that(text, is_not(empty()))