68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""Тесты правки disable_splash в config.txt."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from app.services.pi_boot_config_service import (
|
|
_parse_disable_splash_enabled,
|
|
_patch_disable_splash,
|
|
get_rainbow_splash_status,
|
|
set_rainbow_splash_disabled,
|
|
)
|
|
|
|
|
|
SAMPLE_CONFIG = """# comment
|
|
dtparam=audio=on
|
|
|
|
[cm4]
|
|
otg_mode=1
|
|
|
|
[all]
|
|
enable_uart=1
|
|
"""
|
|
|
|
|
|
class PiBootConfigPatchTests(unittest.TestCase):
|
|
def test_parse_disabled(self) -> None:
|
|
self.assertFalse(_parse_disable_splash_enabled(SAMPLE_CONFIG))
|
|
self.assertTrue(
|
|
_parse_disable_splash_enabled(SAMPLE_CONFIG + "\ndisable_splash=1\n")
|
|
)
|
|
|
|
def test_patch_enable_inserts_under_all(self) -> None:
|
|
out = _patch_disable_splash(SAMPLE_CONFIG, True)
|
|
self.assertIn("disable_splash=1", out)
|
|
lines = out.splitlines()
|
|
all_idx = next(i for i, l in enumerate(lines) if l.strip() == "[all]")
|
|
splash_idx = next(i for i, l in enumerate(lines) if l.strip() == "disable_splash=1")
|
|
self.assertEqual(splash_idx, all_idx + 1)
|
|
|
|
def test_patch_disable_removes_line(self) -> None:
|
|
enabled = _patch_disable_splash(SAMPLE_CONFIG, True)
|
|
disabled = _patch_disable_splash(enabled, False)
|
|
self.assertNotIn("disable_splash", disabled)
|
|
|
|
def test_set_on_temp_file(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "config.txt"
|
|
path.write_text(SAMPLE_CONFIG, encoding="utf-8")
|
|
result = set_rainbow_splash_disabled(True, config_path=str(path))
|
|
self.assertTrue(result.get("ok"))
|
|
text = path.read_text(encoding="utf-8")
|
|
self.assertTrue(_parse_disable_splash_enabled(text))
|
|
|
|
def test_status_temp_file(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = Path(tmp) / "config.txt"
|
|
path.write_text(SAMPLE_CONFIG, encoding="utf-8")
|
|
st = get_rainbow_splash_status(str(path))
|
|
self.assertTrue(st["config_found"])
|
|
self.assertFalse(st["disable_splash"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|