Spaces:
Paused
Paused
File size: 825 Bytes
e40dce0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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}"
)
|