Files
polygon/tests/test_loader.py
T

71 lines
2.0 KiB
Python

"""Regression tests for startup configuration path resolution."""
import os
import subprocess
import sys
from pathlib import Path
import pytest
POLYGON_ROOT = Path(__file__).resolve().parents[1]
SITE_DIR = POLYGON_ROOT / "site"
@pytest.mark.parametrize("working_dir", [POLYGON_ROOT, SITE_DIR])
def test_loader_finds_stand_yaml_independent_of_working_directory(working_dir):
"""Exercise a fresh import from both documented launch directories.
A subprocess isolates module-level environment parsing and import-time YAML
loading, which is the exact behavior used when the WSGI process starts.
"""
env = os.environ.copy()
env["POLYGON_STANDS"] = (
"dev:services/dev,test:services/test,prod:services/prod"
)
python_path = str(SITE_DIR)
if env.get("PYTHONPATH"):
python_path += os.pathsep + env["PYTHONPATH"]
env["PYTHONPATH"] = python_path
subprocess.run(
[
sys.executable,
"-c",
(
"import app; "
"assert set(app._cfg.STANDS) == {'dev', 'test', 'prod'}; "
"assert app.app.test_client().get('/health').status_code == 200"
),
],
cwd=working_dir,
env=env,
check=True,
timeout=10,
)
def test_loader_finds_default_services_from_repository_root():
"""The no-env default must also work with the platform's root CWD."""
env = os.environ.copy()
env.pop("POLYGON_STANDS", None)
python_path = str(SITE_DIR)
if env.get("PYTHONPATH"):
python_path += os.pathsep + env["PYTHONPATH"]
env["PYTHONPATH"] = python_path
subprocess.run(
[
sys.executable,
"-c",
(
"import app; "
"assert set(app._cfg.STANDS) == {'default'}; "
"assert app.app.test_client().get('/health').status_code == 200"
),
],
cwd=POLYGON_ROOT,
env=env,
check=True,
timeout=10,
)