示例工程 32-capstone-publishable-package
32-capstone-publishable-package/05-ci-equivalent/test_ci_equivalent.py
"""test_ci_equivalent.py"""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
from ci_equivalent import main, run_steps
def test_steps_pass() -> None:
ok, completed, logs = run_steps(
[
[sys.executable, "-c", "print('lint ok')"],
[sys.executable, "-c", "print('tests ok')"],
],
Path.cwd(),
)
assert ok is True
assert completed == 2
assert logs == ["lint ok", "tests ok"]
def test_fail_fast() -> None:
ok, failed_at, logs = run_steps(
[
[sys.executable, "-c", "print('one')"],
[sys.executable, "-c", "raise SystemExit(3)"],
[sys.executable, "-c", "print('never')"],
],
Path.cwd(),
)
assert ok is False
assert failed_at == 1
assert len(logs) == 2
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "passed: True" in out
assert "failed_at: 1" in out