okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0c53372a0
main
1"""setup.find_tool takes the virtualenv's own cmake before a PATH one and skips a cmake older than CMakeLists.txt needs (#3822). 2 3python -m unittest tools.test_setup_find_tool 4""" 5from __future__import annotations 6 7import sys 8import tempfile 9import unittest 10from pathlib import Path 11from unittest import mock 12 13ROOT = Path (__file__ ).resolve ().parents [1 ] 14sys .path .insert (0 ,str (ROOT )) 15import setup # noqa: E402 16 17 18class FindTool (unittest .TestCase ): 19def setUp (self ): 20self .tmp = tempfile .TemporaryDirectory () 21self .addCleanup (self .tmp .cleanup ) 22self .bin = Path (self .tmp .name )/ "venv" / "bin" 23self .bin .mkdir (parents = True ) 24self .venv_python = self .bin / "python" 25 26def versions (self ,table ): 27return lambda path ,name :table .get (str (path ), (False , ())) 28 29def venv_tool (self ,name = "cmake" ): 30return str (self .bin / (name + (".exe" if setup .WIN else "" ))) 31 32def find (self ,table ,on_path ,name = "cmake" ,venv_copy = True ): 33if venv_copy : 34Path (self .venv_tool (name )).write_text ("x" ) 35with mock .patch .object (setup .sys ,"executable" ,str (self .venv_python )), \ 36mock .patch .object (setup .shutil ,"which" ,return_value = on_path ), \ 37mock .patch .object (setup ,"_tool_version" ,side_effect = self .versions (table )), \ 38mock .patch .object (setup .Path ,"home" ,return_value = Path (self .tmp .name )/ "home" ): 39return setup .find_tool (name ),setup .tool_usable (name ) 40 41def test_the_virtualenv_copy_wins_over_an_old_system_cmake (self ): 42got ,usable = self .find ({"/usr/bin/cmake" : (True , (3 ,22 ,1 )),self .venv_tool (): (True , (4 ,1 ,0 ))},"/usr/bin/cmake" ) 43self .assertEqual (got ,self .venv_tool ()) 44self .assertTrue (usable ) 45 46def test_an_old_cmake_on_its_own_is_returned_but_not_usable (self ): 47got ,usable = self .find ({"/usr/bin/cmake" : (True , (3 ,22 ,1 ))},"/usr/bin/cmake" ,venv_copy = False ) 48self .assertEqual (got ,"/usr/bin/cmake" )# the build would say "CMake 3.24 or higher is required" 49self .assertFalse (usable )# so setup installs the pip cmake first 50 51def test_a_new_enough_system_cmake_is_fine_without_a_venv_one (self ): 52got ,usable = self .find ({"/usr/bin/cmake" : (True , (3 ,28 ,3 ))},"/usr/bin/cmake" ,venv_copy = False ) 53self .assertEqual ((got ,usable ), ("/usr/bin/cmake" ,True )) 54 55def test_ninja_has_no_version_floor (self ): 56got ,usable = self .find ({"/usr/bin/ninja" : (True , (1 ,10 ))},"/usr/bin/ninja" ,"ninja" ,venv_copy = False ) 57self .assertTrue (usable ) 58 59def test_a_launcher_that_does_not_run_is_skipped (self ): 60got ,_ = self .find ({self .venv_tool (): (False , ()),"/usr/bin/cmake" : (True , (3 ,30 ,0 ))},"/usr/bin/cmake" ) 61self .assertEqual (got ,"/usr/bin/cmake" ) 62 63 64if __name__ == "__main__" : 65unittest .main ()