From 4dff8f11895a7d3d9a555c9e373810e83a2d70d1 Mon Sep 17 00:00:00 2001 From: James McCorrie Date: Wed, 7 Jan 2026 19:11:47 +0000 Subject: [PATCH 1/3] test: static content rendering Signed-off-by: James McCorrie --- tests/templates/__init__.py | 5 +++++ tests/templates/test_render.py | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/templates/__init__.py create mode 100644 tests/templates/test_render.py 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())) From 7d6021004755cc438314d12ae51f294f0583dc4e Mon Sep 17 00:00:00 2001 From: James McCorrie Date: Wed, 7 Jan 2026 19:20:49 +0000 Subject: [PATCH 2/3] ci: prevent fail fast It's useful to have the tests run for all Python versions even if one version has failed. Where there is a breaking change in the API it's really useful to be able to see in which version it starts to fail. Signed-off-by: James McCorrie --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) 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" From 54e59a4379ea1ddf1d463ea83cb62f856a9219cf Mon Sep 17 00:00:00 2001 From: James McCorrie Date: Thu, 8 Jan 2026 11:01:38 +0000 Subject: [PATCH 3/3] fix: render_static works pre python 3.13 Signed-off-by: James McCorrie --- src/dvsim/templates/render.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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, )