okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b247f4ecd
main
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 5python -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 ): 26def test_it_is_the_cmake_project_version (self ): 27with 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" ) 29self .assertEqual (updater .source_tree_version (Path (t )),"0.1.56" ) 30 31def test_nothing_to_read_is_none (self ): 32with tempfile .TemporaryDirectory ()as t : 33self .assertIsNone (updater .source_tree_version (Path (t ))) 34 (Path (t )/ "CMakeLists.txt" ).write_text ("project(other LANGUAGES C)\n" ,encoding = "utf-8" ) 35self .assertIsNone (updater .source_tree_version (Path (t ))) 36 37def test_this_checkout_has_a_version (self ): 38self .assertRegex (updater .source_tree_version ()or "" ,r"^\d+(\.\d+)+$" ) 39 40 41def _report (installed ): 42return {"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 ): 49def _line (self ,installed ,source ): 50out = io .StringIO () 51with mock .patch .object (update_cmd ,"_source_version" ,return_value = source ),contextlib .redirect_stdout (out ): 52update_cmd ._print_check (_report (installed )) 53return next (ln for ln in out .getvalue ().splitlines ()if ln .startswith (" Control" )) 54 55def test_a_checkout_shows_its_own_version (self ): 56self .assertEqual (self ._line (None ,"0.1.56" )," Control 0.1.56: available (0.1.56)" ) 57 58def test_an_installed_control_is_shown_as_it_was (self ): 59self .assertEqual (self ._line ("0.1.55" ,"0.1.56" )," Control 0.1.55: available (0.1.56)" ) 60 61def test_nothing_known_is_still_a_question_mark (self ): 62self .assertEqual (self ._line (None ,None )," Control ?: available (0.1.56)" ) 63 64 65class DecisionIsUnchanged (unittest .TestCase ): 66def test_the_staging_decision_does_not_look_at_the_source_tree (self ): 67feed = SimpleNamespace (control = [SimpleNamespace (platform = "linux-x86_64" ,version = "0.1.56" ,size = 123 )]) 68ctx = SimpleNamespace (hardware = {"platform" :"linux-x86_64" },components = Path ("." )) 69with mock .patch .object (updater ,"active_control" ,return_value = None ),mock .patch .object (ec ,"runtime_version" ,return_value = None ), \ 70mock .patch .object (updater ,"source_tree_version" ,side_effect = AssertionError ("decide_control must not read the source tree" )): 71report = updater .decide_control (feed ,ctx ,None ) 72self .assertEqual ((report ["installed" ],report ["status" ]), (None ,"available" )) 73 74 75if __name__ == "__main__" : 76unittest .main ()