Files
lix/tests/functional2/testlib/fixtures/test_formatter.py
T
Commentator2.0 427696a58d fix codestyle of functional2
Fixing up codestyle issues found within functional2 for later adding
ruff formatter

Change-Id: I0b280587c8243137184091a6d36df3dfe7568eb7
2025-05-10 21:13:45 +02:00

30 lines
1.1 KiB
Python

from string import Template
import pytest
def test_template_balanced_kwargs(balanced_templater: type[Template]):
assert balanced_templater("@test_str@").substitute(test_str="valid") == "valid"
def test_template_balanced_multi_use(balanced_templater: type[Template]):
assert balanced_templater("@test_str@ @test_str@").substitute(test_str="valid") == "valid valid"
def test_balanced_escapement(balanced_templater: type[Template]):
assert balanced_templater("@@ @@{test} @{test}@").substitute(test="t") == "@ @{test} t"
# And that correct exceptions get thrown
def test_template_balanced_extra_kwarg(balanced_templater: type[Template]):
with pytest.raises(ExceptionGroup) as excinfo:
balanced_templater("{test_str}").substitute(test_str="valid", random_str="random")
assert excinfo.group_contains(KeyError, match=r"random_str")
assert not excinfo.group_contains(ValueError)
def test_template_balanced_missing_arg(balanced_templater: type[Template]):
with pytest.raises(KeyError) as e:
balanced_templater("@TEST@ @MISSING@").substitute(TEST="valid")
assert e.match("MISSING")