Public Access
DEVX-12: feat: add opentofu helpers, CLI entry points, shared utility, and CI improvements
Post-merge / detect-type (push) Successful in 11s
Post-merge / validate-commit-msg (push) Successful in 9s
Post-merge / configure-repo (push) Successful in 17s
Post-merge / release (push) Successful in 1m22s
Post-merge / vikunja (push) Successful in 32s
Post-merge / badges (push) Successful in 50s
Post-merge / sync-wiki (push) Successful in 57s
Post-merge / detect-type (push) Successful in 11s
Post-merge / validate-commit-msg (push) Successful in 9s
Post-merge / configure-repo (push) Successful in 17s
Post-merge / release (push) Successful in 1m22s
Post-merge / vikunja (push) Successful in 32s
Post-merge / badges (push) Successful in 50s
Post-merge / sync-wiki (push) Successful in 57s
This commit was merged in pull request #22.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -223,3 +224,66 @@ class TestMain:
|
||||
result = runner.invoke(push_badges.main, ["--output-dir", str(badges_dir), "--no-readme-update"])
|
||||
assert result.exit_code == 0
|
||||
mock_update.assert_not_called()
|
||||
|
||||
def test_retries_success_on_second_attempt(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""With --retries 3, first attempt fails but second succeeds."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
badges_dir = tmp_path / ".badges"
|
||||
badges_dir.mkdir()
|
||||
(badges_dir / "badge1.svg").touch()
|
||||
|
||||
import subprocess
|
||||
|
||||
call_count = [0]
|
||||
|
||||
def side_effect(*args: Any, **kwargs: Any) -> Any:
|
||||
call_count[0] += 1
|
||||
# First call (git fetch) fails, rest succeed
|
||||
if call_count[0] == 1:
|
||||
raise subprocess.CalledProcessError(1, "git fetch")
|
||||
return MagicMock(returncode=0, stdout="", stderr="")
|
||||
|
||||
runner = CliRunner()
|
||||
with (
|
||||
patch("subprocess.run", side_effect=side_effect),
|
||||
patch("devx.ci.push_badges.update_readme_with_badge_sha"),
|
||||
patch("time.sleep"),
|
||||
):
|
||||
result = runner.invoke(
|
||||
push_badges.main,
|
||||
["--output-dir", str(badges_dir), "--no-readme-update", "--retries", "3"],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_retries_exhausted(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""With --retries 2, all attempts fail and exit code is non-zero."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
import subprocess
|
||||
|
||||
runner = CliRunner()
|
||||
with (
|
||||
patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "git fetch")),
|
||||
patch("time.sleep"),
|
||||
):
|
||||
result = runner.invoke(
|
||||
push_badges.main,
|
||||
["--no-readme-update", "--retries", "2"],
|
||||
)
|
||||
assert result.exit_code != 0
|
||||
assert "failed after 2" in result.output
|
||||
|
||||
def test_default_retries_is_one(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Without --retries, only one attempt is made (no retry on failure)."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
||||
import subprocess
|
||||
|
||||
runner = CliRunner()
|
||||
with (
|
||||
patch("subprocess.run", side_effect=subprocess.CalledProcessError(1, "git fetch")),
|
||||
patch("time.sleep") as mock_sleep,
|
||||
):
|
||||
result = runner.invoke(push_badges.main, ["--no-readme-update"])
|
||||
assert result.exit_code != 0
|
||||
mock_sleep.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user