Spaces:
Paused
Paused
Download tests/test_template_syntax.py from BPEL/otree-server: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/spaces/BPEL/otree-server/resolve/main/tests/test_template_syntax.py
- Command line
-
hf download hf://spaces/BPEL/otree-server/tests/test_template_syntax.py
-
curl -L -o test_template_syntax.py https://huggingface.co/spaces/BPEL/otree-server/resolve/main/tests/test_template_syntax.py
825 Bytes
| 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}" | |
| ) | |