示例工程 39-ci-cd-release-pipeline

39-ci-cd-release-pipeline/03-frozen-sync/test_frozen_sync.py

python · 1.0 KB

"""test_frozen_sync.py"""
 
from __future__ import annotations
 
import shutil
from pathlib import Path
 
import pytest
 
pytest.importorskip("subprocess")
 
from frozen_sync import main, make_drifted_copy, uv_check
 
 
def _project() -> Path:
    return Path(__file__).resolve().parents[3]
 
 
@pytest.mark.skipif(shutil.which("uv") is None, reason="需要 uv")
def test_clean_lock_passes() -> None:
    code, _ = uv_check(_project())
    assert code == 0
 
 
@pytest.mark.skipif(shutil.which("uv") is None, reason="需要 uv")
def test_drift_is_detected(tmp_path: Path) -> None:
    drifted = make_drifted_copy(_project(), tmp_path)
    code, message = uv_check(drifted)
    assert code != 0
    assert "needs to be updated" in message
 
 
@pytest.mark.skipif(shutil.which("uv") is None, reason="需要 uv")
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
    main()
    out = capsys.readouterr().out
    assert "clean_exit: 0" in out
    assert "drift_mentions_lock: True" in out