mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
- Add utils/gha/annotations.py with warning/error/notice helpers and *_each variants that emit one annotation per list item - Use warning() in GHCRProvider._set_public for missing GHCR_PAT case - Expose GHCR_PAT_SET env var in mirror step to distinguish missing-PAT from real API failures - Add unit tests for all annotation functions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
from io import StringIO
|
|
from unittest.mock import patch
|
|
|
|
from utils.gha.annotations import error, error_each, notice, warning, warning_each
|
|
|
|
|
|
class TestAnnotations(unittest.TestCase):
|
|
def _capture(self, fn, *args, **kwargs) -> str:
|
|
with patch("sys.stdout", new_callable=StringIO) as mock_out:
|
|
fn(*args, **kwargs)
|
|
return mock_out.getvalue().strip()
|
|
|
|
def test_warning_no_props(self) -> None:
|
|
out = self._capture(warning, "something went wrong")
|
|
self.assertEqual(out, "::warning::something went wrong")
|
|
|
|
def test_warning_with_title(self) -> None:
|
|
out = self._capture(warning, "msg", title="My Title")
|
|
self.assertEqual(out, "::warning title=My Title::msg")
|
|
|
|
def test_warning_with_file_and_line(self) -> None:
|
|
out = self._capture(warning, "msg", file="foo.py", line=42)
|
|
self.assertEqual(out, "::warning file=foo.py,line=42::msg")
|
|
|
|
def test_error_with_title(self) -> None:
|
|
out = self._capture(error, "bad", title="Oops")
|
|
self.assertEqual(out, "::error title=Oops::bad")
|
|
|
|
def test_notice_no_props(self) -> None:
|
|
out = self._capture(notice, "info")
|
|
self.assertEqual(out, "::notice::info")
|
|
|
|
def test_warning_each_emits_one_per_item(self) -> None:
|
|
with patch("sys.stdout", new_callable=StringIO) as mock_out:
|
|
warning_each(["alpha", "beta", "gamma"], title="T")
|
|
lines = mock_out.getvalue().splitlines()
|
|
self.assertEqual(len(lines), 3)
|
|
self.assertIn("alpha", lines[0])
|
|
self.assertIn("beta", lines[1])
|
|
self.assertIn("gamma", lines[2])
|
|
|
|
def test_error_each_emits_one_per_item(self) -> None:
|
|
with patch("sys.stdout", new_callable=StringIO) as mock_out:
|
|
error_each(["x", "y"], title="E")
|
|
lines = mock_out.getvalue().splitlines()
|
|
self.assertEqual(len(lines), 2)
|
|
self.assertTrue(all("::error" in line for line in lines))
|
|
|
|
def test_warning_each_empty(self) -> None:
|
|
with patch("sys.stdout", new_callable=StringIO) as mock_out:
|
|
warning_each([])
|
|
self.assertEqual(mock_out.getvalue(), "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|