okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-0213-qatui (final d33d45ade) into f-0213-intb247f4ecd

main
3.7 KiB76 linesraw
1"""Round 0213 QATUI: `strata update --check` on a SOURCE checkout printed `Control  ?: available (0.1.56)`: no installed Control and no VERSION file, so the version
2was unknown. A checkout runs its own tree: what is PRINTED is the project version in CMakeLists.txt, as `strata --version` says (build 0.1.56).
3Display only (owner 11-04): `decide_control`, which decides whether a Control copy is staged, works exactly as before.
4
5    python -m pytest tests/terminal/test_update_control_source_0213_qatui.py
6"""
7from __future__ import annotations
8
9import contextlib
10import io
11import sys
12import tempfile
13import unittest
14from pathlib import Path
15from types import SimpleNamespace
16from unittest import mock
17
18ROOT = Path(__file__).resolve().parents[2]
19sys.path.insert(0, str(ROOT))
20
21from strata_cli import update_cmd  # noqa: E402
22from strata_control import engine_component as ec, updater  # noqa: E402
23
24
25class SourceTreeVersion(unittest.TestCase):
26    def test_it_is_the_cmake_project_version(self):
27        with tempfile.TemporaryDirectory() as t:
28            (Path(t) / "CMakeLists.txt").write_text("cmake_minimum_required(VERSION 3.20)\nproject(strata VERSION 0.1.56 LANGUAGES CXX)\n", encoding="utf-8")
29            self.assertEqual(updater.source_tree_version(Path(t)), "0.1.56")
30
31    def test_nothing_to_read_is_none(self):
32        with tempfile.TemporaryDirectory() as t:
33            self.assertIsNone(updater.source_tree_version(Path(t)))
34            (Path(t) / "CMakeLists.txt").write_text("project(other LANGUAGES C)\n", encoding="utf-8")
35            self.assertIsNone(updater.source_tree_version(Path(t)))
36
37    def test_this_checkout_has_a_version(self):
38        self.assertRegex(updater.source_tree_version() or "", r"^\d+(\.\d+)+$")
39
40
41def _report(installed):
42    return {"feed": {"sequence": 1, "channel": "stable", "key_id": "k", "trusted_by": "test"},
43            "engine": {"installed": None, "offered": None, "status": "not-in-feed", "download_bytes": 0},
44            "control": {"installed": installed, "offered": "0.1.56", "status": "available", "download_bytes": 1},
45            "app": {"status": "not-in-feed", "installed": None, "offered": None}}
46
47
48class PrintedLine(unittest.TestCase):
49    def _line(self, installed, source):
50        out = io.StringIO()
51        with mock.patch.object(update_cmd, "_source_version", return_value=source), contextlib.redirect_stdout(out):
52            update_cmd._print_check(_report(installed))
53        return next(ln for ln in out.getvalue().splitlines() if ln.startswith("  Control"))
54
55    def test_a_checkout_shows_its_own_version(self):
56        self.assertEqual(self._line(None, "0.1.56"), "  Control  0.1.56: available (0.1.56)")
57
58    def test_an_installed_control_is_shown_as_it_was(self):
59        self.assertEqual(self._line("0.1.55", "0.1.56"), "  Control  0.1.55: available (0.1.56)")
60
61    def test_nothing_known_is_still_a_question_mark(self):
62        self.assertEqual(self._line(None, None), "  Control  ?: available (0.1.56)")
63
64
65class DecisionIsUnchanged(unittest.TestCase):
66    def test_the_staging_decision_does_not_look_at_the_source_tree(self):
67        feed = SimpleNamespace(control=[SimpleNamespace(platform="linux-x86_64", version="0.1.56", size=123)])
68        ctx = SimpleNamespace(hardware={"platform": "linux-x86_64"}, components=Path("."))
69        with mock.patch.object(updater, "active_control", return_value=None), mock.patch.object(ec, "runtime_version", return_value=None), \
70                mock.patch.object(updater, "source_tree_version", side_effect=AssertionError("decide_control must not read the source tree")):
71            report = updater.decide_control(feed, ctx, None)
72        self.assertEqual((report["installed"], report["status"]), (None, "available"))
73
74
75if __name__ == "__main__":
76    unittest.main()