Public Access
Post-merge / detect-type (push) Successful in 10s
Post-merge / validate-commit-msg (push) Successful in 10s
Post-merge / configure-repo (push) Successful in 20s
Post-merge / release (push) Successful in 47s
Post-merge / vikunja (push) Successful in 20s
Post-merge / sync-wiki (push) Successful in 50s
Post-merge / badges (push) Successful in 1m0s
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
"""Unit tests for devx.molecule.platforms."""
|
|
|
|
import json
|
|
|
|
from devx.molecule.platforms import PLATFORMS, load_platforms
|
|
|
|
|
|
class TestPlatforms:
|
|
def test_platforms_not_empty(self) -> None:
|
|
assert len(PLATFORMS) >= 1
|
|
|
|
def test_each_platform_has_required_keys(self) -> None:
|
|
for p in PLATFORMS:
|
|
assert "name" in p
|
|
assert "image" in p
|
|
assert "command" in p
|
|
|
|
def test_platform_names_unique(self) -> None:
|
|
names = [p["name"] for p in PLATFORMS]
|
|
assert len(names) == len(set(names))
|
|
|
|
def test_platforms_use_sleep_infinity(self) -> None:
|
|
"""All default platforms must use sleep infinity, not systemd."""
|
|
for p in PLATFORMS:
|
|
assert p["command"] == "sleep infinity", f"Platform {p['name']} uses {p['command']}"
|
|
|
|
def test_known_platforms_present(self) -> None:
|
|
names = {p["name"] for p in PLATFORMS}
|
|
assert "ubuntu-2604" in names
|
|
|
|
|
|
class TestLoadPlatforms:
|
|
def test_load_platforms_default(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
|
"""load_platforms with no file returns PLATFORMS."""
|
|
result = load_platforms(None)
|
|
assert result == PLATFORMS
|
|
|
|
def test_load_platforms_from_file(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
|
"""load_platforms reads custom platforms from JSON file."""
|
|
custom = [
|
|
{"name": "custom-os", "image": "custom:latest", "command": "sleep infinity"},
|
|
]
|
|
f = tmp_path / "platforms.json"
|
|
f.write_text(json.dumps(custom))
|
|
result = load_platforms(f)
|
|
assert result == custom
|
|
|
|
def test_load_platforms_missing_file_falls_back(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
|
"""load_platforms falls back to PLATFORMS when file doesn't exist."""
|
|
result = load_platforms(tmp_path / "nonexistent.json")
|
|
assert result == PLATFORMS
|
|
|
|
def test_load_platforms_empty_list_falls_back(self, tmp_path) -> None: # type: ignore[no-untyped-def]
|
|
"""load_platforms falls back to PLATFORMS when file has empty list."""
|
|
f = tmp_path / "platforms.json"
|
|
f.write_text("[]")
|
|
result = load_platforms(f)
|
|
assert result == PLATFORMS
|