otree-server / tests /test_template_syntax.py
BPEL Bot
Initial Hugging Face deployment
e40dce0
from pathlib import Path
import re
PROJECT_DIR = Path(__file__).resolve().parents[1]
TEMPLATE_EXPR = re.compile(r"{{\s*([^}]*)\s*}}")
def _exprs_in(path: Path):
text = path.read_text(encoding='utf-8')
return TEMPLATE_EXPR.findall(text)
def test_no_arithmetic_in_templates_public_goods_instructions():
"""oTree's template engine does not support arithmetic in expressions.
This catches cases like `{{ C.PLAYERS_PER_GROUP - 1 }}` or `{{ 60*C.MULTIPLIER }}`.
"""
tpl = PROJECT_DIR / 'public_goods_simple' / 'instructions.html'
assert tpl.exists(), 'Expected public_goods_simple/instructions.html to exist'
for expr in _exprs_in(tpl):
assert not any(op in expr for op in ('-', '*', '/', '+')), (
f"Unsupported arithmetic found in template expression: {expr}"
)