85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def _run_relocated(
|
|
relocated: Path, data_root: Path, *args: str
|
|
) -> subprocess.CompletedProcess[str]:
|
|
env = os.environ.copy()
|
|
for name in tuple(env):
|
|
if name.startswith("GYXX_LEGACY_"):
|
|
env.pop(name)
|
|
env["PYTHONPATH"] = str(relocated / "src")
|
|
env["GYXX_DATA_ROOT"] = str(data_root)
|
|
return subprocess.run(
|
|
[sys.executable, "-m", "gyxx_flow", *args],
|
|
cwd=relocated,
|
|
env=env,
|
|
text=True,
|
|
encoding="utf-8",
|
|
capture_output=True,
|
|
check=False,
|
|
timeout=60,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def relocated_project(tmp_path: Path) -> Path:
|
|
relocated = tmp_path / "moved-gyxx-flow"
|
|
shutil.copytree(PROJECT_ROOT / "src", relocated / "src")
|
|
shutil.copytree(PROJECT_ROOT / "config", relocated / "config")
|
|
return relocated
|
|
|
|
|
|
def test_catalog_and_scripts_work_after_project_and_data_roots_move(
|
|
relocated_project: Path, tmp_path: Path
|
|
) -> None:
|
|
data_root = tmp_path / "independent-data"
|
|
|
|
workflows = _run_relocated(relocated_project, data_root, "list", "--json")
|
|
scripts = _run_relocated(
|
|
relocated_project, data_root, "scripts", "list", "--json"
|
|
)
|
|
|
|
assert workflows.returncode == 0, workflows.stderr
|
|
assert scripts.returncode == 0, scripts.stderr
|
|
assert len(json.loads(workflows.stdout)) == 29
|
|
commands = json.loads(scripts.stdout)
|
|
assert len(commands) == 41
|
|
assert len({row["command_id"] for row in commands}) == 41
|
|
assert all(row["legacy_script_id"].startswith(f"{row['module']}:") for row in commands)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"workflow_id",
|
|
(
|
|
"content.metrics.daily",
|
|
"product.daily",
|
|
"shop.metrics.weekly",
|
|
"supply.purchase_confirmation.daily",
|
|
),
|
|
)
|
|
def test_each_relocated_module_dry_runs_without_old_projects(
|
|
relocated_project: Path, tmp_path: Path, workflow_id: str
|
|
) -> None:
|
|
result = _run_relocated(
|
|
relocated_project,
|
|
tmp_path / "independent-data",
|
|
"run",
|
|
workflow_id,
|
|
"--date",
|
|
"2026-07-27",
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|