mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-11 21:26:44 +00:00
Merge upstream/main into feature/role-stalwart-mail-swarm
This commit is contained in:
971 files changed
+24099
-4900
No files matched your search
@@ -0,0 +1,108 @@
|
||||
"""Unit tests for utils.github.run_name: the emoji head each input's segment
|
||||
opens with, the openings that terminate a value, and the round trip through
|
||||
the declared run name."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from tests.utils.ci.run_name import render
|
||||
from utils.github import run_name
|
||||
|
||||
TPL = (
|
||||
"🕹️ "
|
||||
"${{ inputs.sequencing != 'auto'"
|
||||
" && format('🐛{0} ', inputs.sequencing == 'serial' && '序' || '并') || '' }}"
|
||||
"${{ inputs.mode_fail_fast && '🛑 ' || '' }}"
|
||||
"${{ inputs.workspace != 'auto'"
|
||||
" && format('🧑{0} ', inputs.workspace == 'true' && '是' || '否') || '' }}"
|
||||
"${{ inputs.distros != '' && format('🐧{0} ', inputs.distros) || '' }}"
|
||||
"${{ inputs.priority != '' && format('⭐{0} ', inputs.priority) || '' }}"
|
||||
"${{ inputs.whitelist != ''"
|
||||
" && format('🎯{0}', inputs.whitelist) || '🔀 diff (origin/main)' }}"
|
||||
)
|
||||
|
||||
|
||||
class SegmentTests(unittest.TestCase):
|
||||
def test_value_segments_map_their_input_to_a_head(self) -> None:
|
||||
self.assertEqual(
|
||||
run_name.heads(TPL),
|
||||
{
|
||||
"sequencing": "🐛",
|
||||
"workspace": "🧑",
|
||||
"distros": "🐧",
|
||||
"priority": "⭐",
|
||||
"whitelist": "🎯",
|
||||
},
|
||||
)
|
||||
|
||||
def test_a_valueless_segment_is_a_marker(self) -> None:
|
||||
self.assertEqual(run_name.markers(TPL), {"mode_fail_fast": "🛑"})
|
||||
|
||||
def test_an_input_without_a_value_segment_is_rejected(self) -> None:
|
||||
with self.assertRaises(ValueError):
|
||||
run_name.value_from_title("🕹️ 🐧arch", "lifecycles", TPL)
|
||||
|
||||
|
||||
class OpeningTests(unittest.TestCase):
|
||||
def test_compared_operands_and_value_glyphs_are_not_openings(self) -> None:
|
||||
found = run_name.openings(TPL)
|
||||
self.assertNotIn("auto", found)
|
||||
self.assertNotIn("true", found)
|
||||
self.assertNotIn("是", found)
|
||||
self.assertNotIn("否", found)
|
||||
self.assertNotIn("序", found)
|
||||
|
||||
def test_the_diff_fallback_is_an_opening(self) -> None:
|
||||
self.assertIn("🔀 diff (origin/main)", run_name.openings(TPL))
|
||||
|
||||
|
||||
class ValueTests(unittest.TestCase):
|
||||
def test_a_following_segment_ends_the_value(self) -> None:
|
||||
title = "🕹️ 🐧debian ubuntu ⭐web-app-x 🎯__ALL__"
|
||||
self.assertEqual(
|
||||
run_name.value_from_title(title, "distros", TPL), "debian ubuntu"
|
||||
)
|
||||
|
||||
def test_the_diff_fallback_ends_the_value(self) -> None:
|
||||
title = "🕹️ 🐧arch 🔀 diff (origin/main)"
|
||||
self.assertEqual(run_name.value_from_title(title, "distros", TPL), "arch")
|
||||
|
||||
def test_a_glyph_reads_back_as_its_value(self) -> None:
|
||||
title = "🕹️ 🧑是 🐧arch"
|
||||
self.assertEqual(run_name.value_from_title(title, "workspace", TPL), "true")
|
||||
|
||||
def test_a_marker_reads_back_by_its_presence(self) -> None:
|
||||
self.assertEqual(
|
||||
run_name.values_from_title("🕹️ 🛑 🐧arch", TPL)["mode_fail_fast"], "true"
|
||||
)
|
||||
self.assertEqual(
|
||||
run_name.values_from_title("🕹️ 🐧arch", TPL)["mode_fail_fast"], "false"
|
||||
)
|
||||
|
||||
def test_a_default_input_records_nothing(self) -> None:
|
||||
title = "🕹️ 🐧arch 🔀 diff (origin/main)"
|
||||
self.assertEqual(run_name.value_from_title(title, "sequencing", TPL), "")
|
||||
|
||||
def test_a_foreign_title_yields_nothing(self) -> None:
|
||||
self.assertEqual(run_name.values_from_title("CI: Pull Request", TPL), {})
|
||||
|
||||
|
||||
class DeclaredTemplateTests(unittest.TestCase):
|
||||
def test_the_declared_run_name_round_trips(self) -> None:
|
||||
dispatched = {
|
||||
"sequencing": "serial",
|
||||
"mode_fail_fast": "true",
|
||||
"test_migration": "false",
|
||||
"workspace": "true",
|
||||
"instructions": "false",
|
||||
"filesystem": "ext4",
|
||||
"distros": "debian arch",
|
||||
"lifecycles": "stable",
|
||||
"modes": "swarm compose",
|
||||
}
|
||||
self.assertEqual(run_name.values_from_title(render(dispatched)), dispatched)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Whitespace-only changes.
+64
-12
@@ -1,4 +1,4 @@
|
||||
"""Unit tests for :mod:`utils.github.variant_bundles`."""
|
||||
"""Unit tests for :mod:`utils.github.variant.bundles`."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -8,7 +8,7 @@ from unittest.mock import patch
|
||||
|
||||
from humanfriendly import parse_size
|
||||
|
||||
from utils.github import variant_bundles as vb
|
||||
from utils.github.variant import bundles as vb
|
||||
|
||||
|
||||
class TestChunkIndices(unittest.TestCase):
|
||||
@@ -184,8 +184,18 @@ class TestMain(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
printed,
|
||||
[
|
||||
{"apps": "web-app-five", "variant": "0,1,2", "variant_slug": "0-1-2"},
|
||||
{"apps": "web-app-five", "variant": "3,4", "variant_slug": "3-4"},
|
||||
{
|
||||
"apps": "web-app-five",
|
||||
"variant": "0,1,2",
|
||||
"variant_slug": "0-1-2",
|
||||
"label": "web-app-five 0,1,2",
|
||||
},
|
||||
{
|
||||
"apps": "web-app-five",
|
||||
"variant": "3,4",
|
||||
"variant_slug": "3-4",
|
||||
"label": "web-app-five 3,4",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
@@ -227,7 +237,12 @@ class TestSwarmMode(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
printed,
|
||||
[
|
||||
{"apps": "web-app-five", "variant": str(i), "variant_slug": str(i)}
|
||||
{
|
||||
"apps": "web-app-five",
|
||||
"variant": str(i),
|
||||
"variant_slug": str(i),
|
||||
"label": f"web-app-five {i}",
|
||||
}
|
||||
for i in range(5)
|
||||
],
|
||||
)
|
||||
@@ -240,8 +255,18 @@ class TestSwarmMode(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
printed,
|
||||
[
|
||||
{"apps": "web-app-bbb", "variant": "0", "variant_slug": "0"},
|
||||
{"apps": "web-app-bbb", "variant": "1", "variant_slug": "1"},
|
||||
{
|
||||
"apps": "web-app-bbb",
|
||||
"variant": "0",
|
||||
"variant_slug": "0",
|
||||
"label": "web-app-bbb 0",
|
||||
},
|
||||
{
|
||||
"apps": "web-app-bbb",
|
||||
"variant": "1",
|
||||
"variant_slug": "1",
|
||||
"label": "web-app-bbb 1",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
@@ -253,10 +278,30 @@ class TestSwarmMode(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
printed,
|
||||
[
|
||||
{"apps": "web-app-five", "variant": "3", "variant_slug": "3"},
|
||||
{"apps": "web-app-five", "variant": "0", "variant_slug": "0"},
|
||||
{"apps": "web-app-bare", "variant": "0", "variant_slug": "0"},
|
||||
{"apps": "web-app-bare", "variant": "1", "variant_slug": "1"},
|
||||
{
|
||||
"apps": "web-app-five",
|
||||
"variant": "3",
|
||||
"variant_slug": "3",
|
||||
"label": "web-app-five 3",
|
||||
},
|
||||
{
|
||||
"apps": "web-app-five",
|
||||
"variant": "0",
|
||||
"variant_slug": "0",
|
||||
"label": "web-app-five 0",
|
||||
},
|
||||
{
|
||||
"apps": "web-app-bare",
|
||||
"variant": "0",
|
||||
"variant_slug": "0",
|
||||
"label": "web-app-bare 0",
|
||||
},
|
||||
{
|
||||
"apps": "web-app-bare",
|
||||
"variant": "1",
|
||||
"variant_slug": "1",
|
||||
"label": "web-app-bare 1",
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
@@ -271,7 +316,14 @@ class TestSwarmMode(unittest.TestCase):
|
||||
self.assertEqual(rc, 0)
|
||||
self.assertEqual(
|
||||
json.loads(mock_print.call_args.args[0]),
|
||||
[{"apps": "web-app-bbb", "variant": "0,1", "variant_slug": "0-1"}],
|
||||
[
|
||||
{
|
||||
"apps": "web-app-bbb",
|
||||
"variant": "0,1",
|
||||
"variant_slug": "0-1",
|
||||
"label": "web-app-bbb 0,1",
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user