1
0
Fork 0

Merging upstream version 0.55+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-04-16 09:02:51 +02:00
parent 6fa0ae40a8
commit 4e2fb0fcc7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
14 changed files with 197 additions and 66 deletions

View file

@ -1,13 +1,34 @@
import jinja2
import pytest
from markupsafe import Markup
@pytest.mark.parametrize("undefined", [jinja2.Undefined, jinja2.StrictUndefined])
@pytest.mark.parametrize("autoescape", [True, False])
def test_prefix_namespace(catalog, folder, folder_t, autoescape):
def test_render_prefixed(catalog, folder, folder_t, autoescape, undefined):
"""Components mounted with a prefix should be able to import other components
from the same folder without specifying the prefix.
"""
catalog.jinja_env.autoescape = autoescape
catalog.jinja_env.undefined = undefined
catalog.add_folder(folder_t, prefix="ui")
(folder / "Test.jinja").write_text("<ui:Title />")
(folder_t / "Title.jinja").write_text("prefix")
html = catalog.render("Test")
assert html == Markup("prefix")
@pytest.mark.parametrize("undefined", [jinja2.Undefined, jinja2.StrictUndefined])
@pytest.mark.parametrize("autoescape", [True, False])
def test_prefix_namespace(catalog, folder, folder_t, autoescape, undefined):
"""Components mounted with a prefix should be able to import other components
from the same folder without specifying the prefix.
"""
catalog.jinja_env.autoescape = autoescape
catalog.jinja_env.undefined = undefined
catalog.add_folder(folder_t, prefix="ui")
(folder / "Title.jinja").write_text("parent")
@ -15,54 +36,60 @@ def test_prefix_namespace(catalog, folder, folder_t, autoescape):
(folder_t / "Title.jinja").write_text("prefix")
(folder_t / "Alert.jinja").write_text("<Title />")
html = catalog.render("ui.Alert")
html = catalog.render("ui:Alert")
assert html == Markup("prefix")
@pytest.mark.parametrize("undefined", [jinja2.Undefined, jinja2.StrictUndefined])
@pytest.mark.parametrize("autoescape", [True, False])
def test_prefix_namespace_sub(catalog, folder, folder_t, autoescape):
def test_prefix_namespace_sub(catalog, folder, folder_t, autoescape, undefined):
"""Components mounted with a prefix should be able to import other components
from the same folder without specifying the prefix, even if those components
are in a subfolder.
"""
catalog.jinja_env.autoescape = autoescape
catalog.jinja_env.undefined = undefined
catalog.add_folder(folder_t, prefix="ui")
(folder / "sub").mkdir()
(folder_t / "sub").mkdir()
(folder / "Title.jinja").write_text("parent")
(folder / "sub").mkdir()
(folder / "sub" / "Title.jinja").write_text("sub/parent")
(folder_t / "Title.jinja").write_text("sub")
(folder_t / "sub").mkdir()
(folder_t / "sub" / "Title.jinja").write_text("sub/prefix")
(folder_t / "Alert.jinja").write_text("<sub.Title />")
html = catalog.render("ui.Alert")
html = catalog.render("ui:Alert")
assert html == Markup("sub/prefix")
@pytest.mark.parametrize("undefined", [jinja2.Undefined, jinja2.StrictUndefined])
@pytest.mark.parametrize("autoescape", [True, False])
def test_prefix_fallback(catalog, folder, folder_t, autoescape):
def test_prefix_fallback(catalog, folder, folder_t, autoescape, undefined):
"""If a component is not found in the folder with the prefix, it should
fallback to the no-prefix folders.
"""
catalog.jinja_env.autoescape = autoescape
catalog.jinja_env.undefined = undefined
catalog.add_folder(folder_t, prefix="ui")
(folder / "Title.jinja").write_text("parent")
(folder_t / "Alert.jinja").write_text("<Title />")
html = catalog.render("ui.Alert")
html = catalog.render("ui:Alert")
assert html == Markup("parent")
@pytest.mark.parametrize("undefined", [jinja2.Undefined, jinja2.StrictUndefined])
@pytest.mark.parametrize("autoescape", [True, False])
def test_prefix_namespace_assets(catalog, folder, folder_t, autoescape):
def test_prefix_namespace_assets(catalog, folder, folder_t, autoescape, undefined):
"""Components import without specifying the prefix should also be
able to auto-import their assets.
"""
catalog.jinja_env.autoescape = autoescape
catalog.jinja_env.undefined = undefined
catalog.add_folder(folder_t, prefix="ui")
(folder_t / "Title.jinja").write_text("prefix")
@ -73,7 +100,7 @@ def test_prefix_namespace_assets(catalog, folder, folder_t, autoescape):
""")
(folder_t / "Alert.jinja").write_text("<Layout><Title /></Layout>")
html = catalog.render("ui.Alert")
html = catalog.render("ui:Alert")
assert html == Markup("""
<link rel="stylesheet" href="/static/components/ui/Title.css">
prefix