54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import os
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
os.environ.setdefault("PW_BACKOFF_SCALE", "0.01")
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
parser.addoption("--live", action="store_true", help="run tests against the real provider (Morph)")
|
|
parser.addoption("--docker", action="store_true", help="run tests that need a Docker daemon")
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
for item in items:
|
|
if "live" in item.keywords and not config.getoption("--live"):
|
|
item.add_marker(pytest.mark.skip(reason="needs --live"))
|
|
if "docker" in item.keywords and not (config.getoption("--docker") or os.environ.get("PW_TEST_DOCKER")):
|
|
item.add_marker(pytest.mark.skip(reason="needs --docker"))
|
|
|
|
|
|
@pytest.fixture
|
|
def make_project(tmp_path):
|
|
"""Write a project file (dict) into tmp_path and return the Project."""
|
|
from pipewright.project import Project
|
|
|
|
def make(cfg: dict | None = None, name: str = "pipewright.yaml"):
|
|
cfg = {"store": ".pipewright", **(cfg or {})}
|
|
(tmp_path / name).write_text(yaml.safe_dump(cfg))
|
|
return Project.load(tmp_path / name)
|
|
|
|
return make
|
|
|
|
|
|
@pytest.fixture
|
|
def example(tmp_path):
|
|
"""Copy an example directory into tmp_path; returns its path."""
|
|
|
|
def copy(name: str) -> Path:
|
|
dst = tmp_path / name
|
|
shutil.copytree(ROOT / "examples" / name, dst,
|
|
ignore=shutil.ignore_patterns(".pipewright*", "out", "__pycache__"))
|
|
return dst
|
|
|
|
return copy
|
|
|
|
|
|
FAKE = {"providers": {"fake": {"type": "fake"}}, "models": {"m": {"provider": "fake", "model": "fake-m"}}}
|