Files
PlantAI-dev/tests/unit/test_start_plantai_9000_script.py
T
2026-08-03 18:42:47 +08:00

59 lines
1.9 KiB
Python

from __future__ import annotations
import os
import subprocess
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
START_SCRIPT = PROJECT_ROOT / "start_plantai_9000.sh"
def test_start_plantai_9000_ignores_sandbox_profile(tmp_path: Path) -> None:
fake_python = tmp_path / "conda" / "envs" / "test4py311" / "bin" / "python"
fake_python.parent.mkdir(parents=True)
fake_python.write_text(
"#!/bin/sh\n"
"printf 'FAKE_PORT=%s\\n' \"$PLANTAI_WEB_PORT\"\n"
"printf 'FAKE_PROJECT=%s\\n' \"$BBAV5_PROJECT_ROOT\"\n"
"printf 'FAKE_PLANTAI_PROJECT=%s\\n' \"$PLANTAI_PROJECT_ROOT\"\n"
"printf 'FAKE_QUEUE=%s\\n' \"$BBAV5_QUEUE_PREFIX\"\n"
"printf 'FAKE_REDIS=%s\\n' \"$BBAV5_REDIS_URL\"\n"
"printf 'FAKE_ARGS=%s\\n' \"$*\"\n",
encoding="utf-8",
)
fake_python.chmod(0o755)
env = os.environ.copy()
env.update(
{
"BBAV5_CONDA_BASE": str(tmp_path / "conda"),
"PLANTAI_WEB_PORT": "19000",
"BBAV5_PROJECT_ROOT": "/tmp/gwas-project",
"PLANTAI_PROJECT_ROOT": "/tmp/gwas-project",
"BBAV5_QUEUE_PREFIX": "plantai_gwas18_test",
"BBAV5_REDIS_URL": "redis://localhost:6379/11",
}
)
completed = subprocess.run(
["bash", str(START_SCRIPT)],
cwd=PROJECT_ROOT,
env=env,
check=True,
text=True,
capture_output=True,
)
output = completed.stdout
assert "URL: http://127.0.0.1:9000" in output
assert f"Project: {PROJECT_ROOT}" in output
assert "Queue prefix: plantai_dev_9000" in output
assert "Redis: redis://localhost:6379/10" in output
assert "FAKE_PORT=9000" in output
assert f"FAKE_PROJECT={PROJECT_ROOT}" in output
assert f"FAKE_PLANTAI_PROJECT={PROJECT_ROOT}" in output
assert "FAKE_QUEUE=plantai_dev_9000" in output
assert "FAKE_REDIS=redis://localhost:6379/10" in output
assert "--port 9000" in output