Coverage for tdom / template_utils_test.py: 100%
27 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-17 23:32 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-17 23:32 +0000
1from string.templatelib import Interpolation
3import pytest
5from .template_utils import TemplateRef, template_from_parts
8def test_template_from_parts() -> None:
9 strings = ("Hello, ", "! Today is ", ".")
10 interpolations = (Interpolation("Alice"), Interpolation("Monday"))
11 template = template_from_parts(strings, interpolations)
12 assert template.strings == strings
13 assert template.interpolations == interpolations
16def test_template_ref_is_literal() -> None:
17 literal_ref = TemplateRef.literal("Hello")
18 assert literal_ref.is_literal
20 non_literal_ref = TemplateRef(("", ""), (0,))
21 assert not non_literal_ref.is_literal
24def test_template_ref_is_empty() -> None:
25 empty_ref = TemplateRef.empty()
26 assert empty_ref.is_empty
28 non_empty_ref = TemplateRef.literal("Hello")
29 assert not non_empty_ref.is_empty
32def test_template_ref_is_singleton() -> None:
33 singleton_ref = TemplateRef.singleton(0)
34 assert singleton_ref.is_singleton
36 non_singleton_ref = TemplateRef.literal("Hello")
37 assert not non_singleton_ref.is_singleton
40def test_template_ref_post_init_validation() -> None:
41 with pytest.raises(ValueError):
42 _ = TemplateRef(("Hello",), (0, 1))