misc: add support for boolean values in ezt (#14279)

This commit is contained in:
Frédéric Péters 2021-10-24 20:17:59 +02:00
parent 96aea1ff53
commit 44a1e2f0e6
2 changed files with 13 additions and 0 deletions

View File

@ -139,6 +139,17 @@ def test_datetime_qualifier(pub):
assert output.getvalue() == '<p>02/01/2019 14:04</p>'
def test_is_bool():
template = Template()
template.parse('<p>[is foo True]hello[end]</p>')
output = io.StringIO()
template.generate(output, {'foo': True})
assert output.getvalue() == '<p>hello</p>'
output = io.StringIO()
template.generate(output, {'foo': False})
assert output.getvalue() == '<p></p>'
def test_unclosed_block():
template = Template()
with pytest.raises(UnclosedBlocksError):

View File

@ -657,6 +657,8 @@ def _get_value(value_ref, ctx):
ob = ctx.defines[start]
elif hasattr(ctx.data, start):
ob = getattr(ctx.data, start)
elif refname in ('True', 'False'):
return bool(refname == 'True')
else:
raise UnknownReference(refname)