okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
d64ae1b0b
main
1"""The engine test start with no model installed: an engine without a --version flag (it prints its options and exits 2) still counts as running.""" 2 3import os 4import stat 5import sys 6import tempfile 7import unittest 8from pathlib import Path 9from types import SimpleNamespace 10 11from strata_control import updater 12 13 14def make_engine (folder :Path ,body_posix :str ,body_nt :str )-> Path : 15if os .name == "nt" : 16path = folder / "strata.cmd" 17path .write_text ("@echo off\r\n" + body_nt ,encoding = "utf-8" ) 18else : 19path = folder / "strata" 20path .write_text ("#!/bin/sh\n" + body_posix ,encoding = "utf-8" ) 21path .chmod (path .stat ().st_mode | stat .S_IXUSR ) 22return path 23 24 25USAGE_POSIX = "echo 'strata generate [options]' >&2\nfor f in a b c d e f; do echo \" --opt-$f N something\" >&2; done\nexit 2\n" 26USAGE_NT = "echo strata generate [options] 1>&2\r\n" + "" .join (f"echo --opt- { c } N something 1>&2\r\n" for c in "abcdef" )+ "exit /b 2\r\n" 27 28 29class BinarySmoke (unittest .TestCase ): 30def component (self ,folder :Path ,exe :Path ): 31return SimpleNamespace (exe = exe ,root = folder ,version = "0.1.45" ) 32 33def test_an_engine_that_lists_its_options_instead_of_answering_version_passes (self ): 34with tempfile .TemporaryDirectory ()as tmp : 35folder = Path (tmp ) 36res = updater .binary_smoke (self .component (folder ,make_engine (folder ,USAGE_POSIX ,USAGE_NT ))) 37self .assertEqual (res ["mode" ],"binary-only" ) 38self .assertIn ("does not answer --version" ,res ["detail" ]) 39self .assertIn ("listed its options" ,res ["detail" ]) 40 41def test_an_engine_that_answers_version_passes_as_before (self ): 42with tempfile .TemporaryDirectory ()as tmp : 43folder = Path (tmp ) 44res = updater .binary_smoke (self .component (folder ,make_engine (folder ,"echo strata 0.1.45\nexit 0\n" ,"echo strata 0.1.45\r\nexit /b 0\r\n" ))) 45self .assertIn ("--version only" ,res ["detail" ]) 46 47def test_a_real_failure_still_fails (self ): 48with tempfile .TemporaryDirectory ()as tmp : 49folder = Path (tmp ) 50exe = make_engine (folder ,"echo 'No device of requested type available' >&2\nexit 250\n" ,"echo No device of requested type available 1>&2\r\nexit /b 250\r\n" ) 51with self .assertRaises (updater .TestStartFailed )as e : 52updater .binary_smoke (self .component (folder ,exe )) 53self .assertIn ("No device of requested type" ,e .exception .reason ) 54 55def test_exit_2_without_a_list_of_options_still_fails (self ): 56with tempfile .TemporaryDirectory ()as tmp : 57folder = Path (tmp ) 58exe = make_engine (folder ,"echo 'bad usage' >&2\nexit 2\n" ,"echo bad usage 1>&2\r\nexit /b 2\r\n" ) 59with self .assertRaises (updater .TestStartFailed ): 60updater .binary_smoke (self .component (folder ,exe )) 61 62 63if __name__ == "__main__" : 64unittest .main ()