Spaces:
Paused
Paused
File size: 1,391 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import os
import subprocess
from pathlib import Path
import time
PROJECT_DIR = Path(__file__).resolve().parents[1]
OTREE = PROJECT_DIR.parents[1] / 'venv' / 'bin' / 'otree'
def run_otree_test(app: str):
env = os.environ.copy()
# Ensure a fresh SQLite DB per test run to avoid schema/version conflicts
db_name = f"test_db_{app}_{int(time.time()*1000)}.sqlite3"
env['OTREE_DATABASE_URL'] = f"sqlite:///{db_name}"
# Also remove default db.sqlite3 if present
default_db = PROJECT_DIR / 'db.sqlite3'
if default_db.exists():
default_db.unlink()
proc = subprocess.run(
[str(OTREE), 'test', app],
cwd=str(PROJECT_DIR),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
env=env,
)
if proc.returncode != 0:
print(proc.stdout)
assert proc.returncode == 0, f"oTree bot tests failed for {app}"
def test_bots_policy_nudges_sequence():
run_otree_test('policy_nudges')
def test_bots_guessing_game_demo_sequence():
run_otree_test('guessing_game_demo')
def test_bots_survey_biases_sequence():
run_otree_test('survey_biases_full')
def test_bots_classic_baseline_sequence():
# Reproduce navigation/rendering issues in the classic baseline sequence
# (e.g., template expressions not supported by oTree's template engine).
run_otree_test('classic_baseline')
|