okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1"""Tests for setup.py's reproducible installs (#214): the engine of the checkout's own release first (the latest as 2the fallback), Hugging Face files at pinned revisions (a gone revision stops the download), the pinned 3requirements file, and an existing install left as it is. Mocked network - nothing is downloaded. 4 5python -m unittest tools.test_setup_pins 6""" 7from __future__import annotations 8 9import contextlib 10import hashlib 11import io 12import json 13import re 14import sys 15import tempfile 16import unittest 17import urllib .error 18import zipfile 19from pathlib import Path 20from unittest import mock 21 22ROOT = Path (__file__ ).resolve ().parents [1 ] 23sys .path .insert (0 ,str (ROOT )) 24sys .path .insert (0 ,str (ROOT / "tools" )) 25import setup # noqa: E402 26 27SHA = re .compile (r"/resolve/[0-9a-f]{40}/" ) 28 29 30class Response (io .BytesIO ): 31def __init__ (self ,body = b"" ,status = 200 ): 32super ().__init__ (body ) 33self .status = status 34self .headers = {"Content-Length" :str (len (body ))} 35 36def __enter__ (self ): 37return self 38 39def __exit__ (self ,* exc ): 40self .close () 41 42 43def not_found (url ): 44return urllib .error .HTTPError (url ,404 ,"Not Found" , {},None ) 45 46 47def quiet (fn ,* args ,** kw ): 48out = io .StringIO () 49with contextlib .redirect_stdout (out ): 50return fn (* args ,** kw ),out .getvalue () 51 52 53class HuggingFacePins (unittest .TestCase ): 54def test_every_model_url_is_pinned (self ): 55for name ,fam in setup .FAMILIES .items (): 56if fam .get ("ready" ):# ready-made packs: pinned per file (test_ready_packs_pinned) 57continue 58for key in ("hf" ,"mmproj_hf" ): 59with self .subTest (family = name ,key = key ): 60self .assertRegex (fam [key ],SHA ) 61self .assertNotIn ("/resolve/main/" ,fam [key ]) 62self .assertRegex (setup .HF ,SHA ) 63 64def test_ready_packs_pinned (self ): 65"""NVFP4: every size names a repository of NVFP4_REPOS, pinned by a commit; every file has a size and a 66SHA-256, and the pack folder, dense GGUF, n-gram table and embedding are each there.""" 67sizes = [m for m ,d in setup .MODELS .items ()if d .get ("repo" )] 68self .assertEqual (sorted (sizes ), ["NVFP4" ,"NVFP4-NVIDIA" ,"NVFP4-QAD" ]) 69for m in sizes : 70if setup .MODELS [m ].get ("prepare" ):# NVIDIA's checkpoint: pinned files, prepared on the PC 71t = setup .NVFP4_REPOS [setup .MODELS [m ]["repo" ]] 72self .assertRegex (t ["revision" ],r"^[0-9a-f]{40}$" ) 73for path , (role ,size ,sha )in t ["files" ].items (): 74self .assertEqual (role ,"src" ) 75self .assertGreater (size ,0 ) 76self .assertRegex (sha ,r"^[0-9a-f]{64}$" ) 77self .assertEqual (sorted (setup .ready_paths (m ,setup .Path ("M" ))), ["dense" ,"mtp" ,"pack" ,"ple" ]) 78continue 79t = setup .NVFP4_REPOS [setup .MODELS [m ]["repo" ]] 80self .assertRegex (t ["revision" ],r"^[0-9a-f]{40}$" ) 81for path , (role ,size ,sha )in t ["files" ].items (): 82with self .subTest (model = m ,path = path ): 83self .assertIn (role , ("pack" ,"dense" ,"ple" ,"embd" )) 84self .assertGreater (size ,0 ) 85self .assertRegex (sha ,r"^[0-9a-f]{64}$" ) 86p = setup .ready_paths (m ,setup .Path ("M" )) 87self .assertEqual (sorted (p ), ["dense" ,"embd" ,"pack" ,"ple" ]) 88self .assertEqual (p ["pack" ].name ,"pack" ) 89self .assertIn ("experts.bin" ,t ["files" ]and [x .split ("/" )[- 1 ]for x in t ["files" ]]) 90 91def test_unpinned (self ): 92url = setup .FAMILIES ["swift" ]["hf" ]+ "x.gguf" 93self .assertEqual (setup .hf_unpinned (url ), 94"https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF/resolve/main/x.gguf" ) 95self .assertEqual (setup .hf_unpinned ("https://example.com/a/b" ),"https://example.com/a/b" ) 96 97def test_a_gone_revision_stops_the_download (self ): 98"""The pinned commit answers 404: setup stops with a plain message and fetches no current file.""" 99seen = [] 100 101def urlopen (req ,timeout = None ): 102seen .append ((req .get_method (),req .full_url )) 103raise not_found (req .full_url ) 104 105with tempfile .TemporaryDirectory ()as d ,mock .patch .object (setup .netpolicy ,"urlopen" ,urlopen ),mock .patch .dict (setup .os .environ , {"STRATA_SOURCE" :"huggingface" }): 106setup .os .environ .pop ("STRATA_ALLOW_UNPINNED" ,None ) 107dst = Path (d )/ "m.gguf" 108with self .assertRaises (SystemExit ): 109_ ,out = quiet (setup .download ,setup .FAMILIES ["qwen" ]["mmproj_hf" ]+ "m.gguf" ,dst ) 110self .assertFalse (dst .exists ()) 111self .assertEqual ([m for m ,_ in seen ], ["HEAD" ]) 112self .assertTrue (all ("/resolve/main/" not in u for _ ,u in seen )) 113 114def test_the_opt_out_downloads_the_current_file (self ): 115"""STRATA_ALLOW_UNPINNED=1 (a tester's choice): the repository's current file, announced, off by default.""" 116seen = [] 117 118def urlopen (req ,timeout = None ): 119seen .append ((req .get_method (),req .full_url )) 120if "/resolve/main/" not in req .full_url : 121raise not_found (req .full_url ) 122return Response (b"model bytes" ,status = 200 ) 123 124# the pinned Hugging Face path itself (setup's --source huggingface; auto may pick ModelScope) 125with tempfile .TemporaryDirectory ()as d ,mock .patch .object (setup .netpolicy ,"urlopen" ,urlopen ),mock .patch .dict (setup .os .environ , {"STRATA_SOURCE" :"huggingface" ,"STRATA_ALLOW_UNPINNED" :"1" }),mock .patch .object (setup ,"_unpinned_said" , []): 126dst = Path (d )/ "m.gguf" 127_ ,out = quiet (setup .download ,setup .FAMILIES ["qwen" ]["mmproj_hf" ]+ "m.gguf" ,dst ) 128self .assertEqual (dst .read_bytes (),b"model bytes" ) 129self .assertIn ("STRATA_ALLOW_UNPINNED=1" ,out ) 130self .assertIn ("not at the pinned revision any more" ,out ) 131self .assertEqual ([m for m ,_ in seen ], ["HEAD" ,"HEAD" ,"GET" ]) 132self .assertTrue (all ("/resolve/main/" in u for _ ,u in seen [1 :])) 133 134def test_a_complete_part_is_finished_without_a_request (self ): 135"""A .part with every byte (setup stopped between the last byte and the rename): renamed, not resumed with a 136range past its end - the server answers that with 416, which download() retried 30 times, 10 s apart.""" 137seen = [] 138 139def urlopen (req ,timeout = None ): 140seen .append ((req .get_method (),req .headers .get ("Range" ))) 141if req .get_method ()== "HEAD" : 142return Response (b"model bytes" ) 143raise urllib .error .HTTPError (req .full_url ,416 ,"Range Not Satisfiable" , {},None ) 144 145with tempfile .TemporaryDirectory ()as d ,mock .patch .object (setup .netpolicy ,"urlopen" ,urlopen ), \ 146mock .patch .object (setup .time ,"sleep" ,lambda s :None ): 147dst = Path (d )/ "m.gguf" 148dst .with_name ("m.gguf.part" ).write_bytes (b"model bytes" ) 149quiet (setup .download ,"https://example.com/m.gguf" ,dst ) 150self .assertEqual (dst .read_bytes (),b"model bytes" ) 151self .assertTrue (setup .done (dst )) 152self .assertEqual (seen , [("HEAD" ,None )]) 153 154def test_mtp_fetch_is_pinned_and_stops_when_the_revision_is_gone (self ): 155import mtp_fetch 156self .assertRegex (mtp_fetch .REPO ,SHA ) 157self .assertIn (mtp_fetch .REVISION ,mtp_fetch .REPO ) 158pinned = mtp_fetch .REPO 159 160def urlopen (req ,timeout = None ): 161raise not_found (req .full_url ) 162 163try : 164with mock .patch .object (mtp_fetch .netpolicy ,"urlopen" ,urlopen ),mock .patch .dict (mtp_fetch .os .environ , {"STRATA_ALLOW_UNPINNED" :"" }): 165with self .assertRaises (SystemExit )as stop : 166mtp_fetch .resolve_repo () 167self .assertIn ("no longer on Hugging Face" ,str (stop .exception )) 168self .assertEqual (mtp_fetch .REPO ,pinned ) 169with mock .patch .object (mtp_fetch .netpolicy ,"urlopen" ,urlopen ),mock .patch .dict (mtp_fetch .os .environ , {"STRATA_ALLOW_UNPINNED" :"1" }),contextlib .redirect_stderr (io .StringIO ())as err : 170self .assertEqual (mtp_fetch .resolve_repo (),"https://huggingface.co/Qwen/Qwen3.8-Flash-Next/resolve/main/" ) 171self .assertIn ("STRATA_ALLOW_UNPINNED=1" ,err .getvalue ()) 172finally : 173mtp_fetch .REPO = pinned 174 175def test_hf_endpoint (self ): 176# #495: HF_ENDPOINT (a mirror) serves the same pinned revision; a trailing slash and blanks are dropped 177repo = "ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF" 178with mock .patch .dict (setup .os .environ , {},clear = False ): 179setup .os .environ .pop ("HF_ENDPOINT" ,None ) 180self .assertEqual (setup .hf (repo ),f"https://huggingface.co/ { repo } /resolve/ { setup . HF_REVISIONS [ repo ] } /" ) 181for value in ("https://hf-mirror.com" ,"https://hf-mirror.com/" ," https://hf-mirror.com/ " ): 182setup .os .environ ["HF_ENDPOINT" ]= value 183url = setup .hf (repo ) 184self .assertEqual (url ,f"https://hf-mirror.com/ { repo } /resolve/ { setup . HF_REVISIONS [ repo ] } /" ) 185self .assertRegex (url ,SHA ) 186self .assertEqual (setup .hf_unpinned (url + "x.gguf" ),f"https://hf-mirror.com/ { repo } /resolve/main/x.gguf" ) 187setup .os .environ ["HF_ENDPOINT" ]= "" 188self .assertEqual (setup .hf_endpoint (),"https://huggingface.co" ) 189 190def test_mtp_fetch_honours_hf_endpoint (self ): 191import importlib 192import mtp_fetch 193try : 194with mock .patch .dict (mtp_fetch .os .environ , {"HF_ENDPOINT" :"https://hf-mirror.com/" }): 195importlib .reload (mtp_fetch ) 196self .assertTrue (mtp_fetch .REPO .startswith ("https://hf-mirror.com/Qwen/Qwen3.8-Flash-Next/resolve/" )) 197self .assertRegex (mtp_fetch .REPO ,SHA ) 198self .assertTrue (mtp_fetch .pinned ())# the tensors' SHA-256 checks still apply 199finally : 200importlib .reload (mtp_fetch ) 201self .assertTrue (mtp_fetch .REPO .startswith ("https://huggingface.co/" )) 202 203def test_step5_names_the_folder (self ): 204# #495: where setup expects the model files, and how to give it files downloaded by hand 205from test_setup_golden import PROFILES ,install 206ram ,found = PROFILES ["96GB-1x16GB" ] 207with mock .patch .dict (setup .os .environ , {"HF_ENDPOINT" :"https://hf-mirror.com" }): 208code ,out ,cfg ,_ = install (ram ,found , ["--family" ,"qwen" ,"--model" ,"IQ3_XXS" ,"--no-start" ]) 209self .assertEqual (code ,0 ) 210text = out .replace ("\\" ,"/" ) 211self .assertRegex (text ,r"The model files go in .*/models/IQ3_XXS" ) 212self .assertIn ("put them here with their original names (Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf" , 213text ) 214self .assertIn ("--gguf-dir" ,text ) 215self .assertIn ("Downloading from https://hf-mirror.com (HF_ENDPOINT)" ,text ) 216 217 218@ unittest . skipIf ( setup . is_arm64 () and sys . platform . startswith ( "linux" ), 219"arm64 Linux takes its ready-made engine from the signed feed, not from the flat x86 zips these tests build " 220"(tests/terminal/test_linux_aarch64.py covers that path)" ) 221class Engine (unittest .TestCase ): 222def setUp (self ): 223self .tmp = tempfile .TemporaryDirectory () 224self .root = Path (self .tmp .name ) 225 (self .root / "engine" ).mkdir () 226self .patches = [mock .patch .object (setup ,"ROOT" ,self .root ), 227mock .patch .object (setup ,"source_version" ,lambda :"0.1.31" )] 228for p in self .patches : 229p .start () 230 231def tearDown (self ): 232for p in reversed (self .patches ): 233p .stop () 234self .tmp .cleanup () 235 236def fake_download (self ,got ,wrote = None ): 237def download (url ,dst ,what = None ): 238got .append (url ) 239if wrote is not None : 240wrote .append (Path (dst )) 241with zipfile .ZipFile (dst ,"w" )as z : 242z .writestr ("BUILD.json" ,json .dumps ({"version" :"." .join (map (str ,setup .MIN_ENGINE )),"archs" : [89 ]})) 243z .writestr (setup .EXE ,b"engine" ) 244return download 245 246def fake_digest (self ,wrote ): 247"""The SHA-256 of whatever the fake download just wrote, computed for real. 248 249`get_prebuilt()` now checks the archive against GitHub's size and SHA-256 before it unpacks 250anything, so a test that mocks the download has to supply a hash or it stops at the check. These 251tests are about WHICH release and WHICH asset are chosen, not about the bytes; what happens when 252the hash is wrong has its own file (tools/test_setup_engine_hash.py). 253""" 254def digest (asset ,base ): 255data = Path (wrote [- 1 ]).read_bytes () 256return len (data ),hashlib .sha256 (data ).hexdigest () 257return digest 258 259def run_get (self ,published ): 260heads ,got ,wrote = [], [], [] 261 262def urlopen (req ,timeout = None ): 263heads .append (req .full_url ) 264if not any (req .full_url .startswith (p )for p in published ): 265raise not_found (req .full_url ) 266return Response () 267 268with mock .patch .object (setup .netpolicy ,"urlopen" ,urlopen ), \ 269mock .patch .object (setup ,"download" ,self .fake_download (got ,wrote )), \ 270mock .patch .object (setup ,"engine_digest" ,self .fake_digest (wrote )): 271eng ,out = quiet (setup .get_prebuilt ,setup .PREBUILT_URL , {"arch" :89 },"gpu" ) 272return eng ,out ,heads ,got 273 274def test_bases (self ): 275self .assertEqual (setup .prebuilt_bases (setup .PREBUILT_URL ), 276 ["https://github.com/Niko1221/Strata/releases/download/v0.1.31/" ,setup .PREBUILT_URL ]) 277self .assertEqual (setup .prebuilt_bases ("https://mirror.example/x" ), ["https://mirror.example/x/" ]) 278 279def test_the_checkout_s_release_first (self ): 280tag = "https://github.com/Niko1221/Strata/releases/download/v0.1.31/" 281eng ,out ,heads ,got = self .run_get ([tag ,setup .PREBUILT_URL ]) 282self .assertEqual (eng ,self .root / "engine" ) 283self .assertEqual (got , [tag + setup .PREBUILT_ASSET ]) 284self .assertEqual (len (heads ),1 ) 285 286def test_latest_when_it_is_not_published (self ): 287eng ,out ,heads ,got = self .run_get ([setup .PREBUILT_URL ]) 288self .assertEqual (eng ,self .root / "engine" ) 289self .assertEqual (got , [setup .PREBUILT_URL + setup .PREBUILT_ASSET ]) 290self .assertIn ("No ready-made engine for v0.1.31" ,out ) 291 292def test_a_refused_archive_is_not_kept (self ): 293"""PR #324: a refused archive (too old, or no code for the GPU) kept its zip and .done mark, and every later 294run reused it ("already downloaded") instead of the published one.""" 295for meta in ({"version" :"0.1.0" ,"archs" : [89 ]}, 296 {"version" :"." .join (map (str ,setup .MIN_ENGINE )),"archs" : [120 ]}): 297with self .subTest (meta = meta ): 298wrote = [] 299 300def download (url ,dst ,what = None ): 301wrote .append (Path (dst )) 302with zipfile .ZipFile (dst ,"w" )as z : 303z .writestr ("BUILD.json" ,json .dumps (meta )) 304z .writestr (setup .EXE ,b"engine" ) 305setup .mark (dst ) 306 307with mock .patch .object (setup .netpolicy ,"urlopen" ,lambda req ,timeout = None :Response ()), \ 308mock .patch .object (setup ,"download" ,download ), \ 309mock .patch .object (setup ,"engine_digest" ,self .fake_digest (wrote )): 310eng ,_ = quiet (setup .get_prebuilt ,setup .PREBUILT_URL , {"arch" :89 },"gpu" ) 311self .assertIsNone (eng ) 312z = self .root / "engine" / setup .PREBUILT_ASSET 313self .assertFalse (z .exists ()) 314self .assertFalse (z .with_name (z .name + ".done" ).exists ()) 315 316def test_an_archive_that_does_not_unpack_is_not_kept (self ): 317"""#397, for an archive that does not unpack (not a zip, or a damaged one): it kept its zip and .done mark, 318so every later run failed on it, even after the right one was published.""" 319with tempfile .TemporaryDirectory ()as folder :# a --prebuilt folder, through the real download() 320asset = Path (folder )/ setup .PREBUILT_ASSET 321asset .write_bytes (b"<html>not a zip</html>" ) 322with self .assertRaises (zipfile .BadZipFile ): 323quiet (setup .get_prebuilt ,folder , {"arch" :89 },"gpu" ) 324with zipfile .ZipFile (asset ,"w" )as z : 325z .writestr ("BUILD.json" ,json .dumps ({"version" :"." .join (map (str ,setup .MIN_ENGINE )),"archs" : [89 ]})) 326z .writestr (setup .EXE ,b"engine" ) 327eng ,_ = quiet (setup .get_prebuilt ,folder , {"arch" :89 },"gpu" ) 328self .assertEqual (eng ,self .root / "engine" ) 329self .assertEqual ((self .root / "engine" / setup .EXE ).read_bytes (),b"engine" ) 330 331def test_an_installed_engine_is_kept (self ): 332 (self .root / "engine" / "BUILD.json" ).write_text (json .dumps ( 333 {"version" :"." .join (map (str ,setup .MIN_ENGINE )),"archs" : [89 ]})) 334 (self .root / "engine" / setup .EXE ).write_bytes (b"old" ) 335 336def urlopen (req ,timeout = None ): 337raise AssertionError ("asked the network for an installed engine" ) 338 339with mock .patch .object (setup .netpolicy ,"urlopen" ,urlopen ): 340eng ,out = quiet (setup .get_prebuilt ,setup .PREBUILT_URL , {"arch" :89 },"gpu" ) 341self .assertEqual (eng ,self .root / "engine" ) 342self .assertEqual ((self .root / "engine" / setup .EXE ).read_bytes (),b"old" ) 343 344 345class Requirements (unittest .TestCase ): 346def test_every_package_is_pinned (self ): 347lines = setup .requirement_lines () 348names = {setup .req_name (x )for x in lines } 349for p in setup .PY_PACKAGES : 350self .assertIn (p ,names ) 351for x in lines : 352self .assertIn ("==" ,x ,x ) 353self .assertEqual (setup .req_name ('numpy==2.5.3; python_version >= "3.12"' ),"numpy" ) 354self .assertEqual (setup .req_name ("charset_normalizer==3" ),"charset-normalizer" ) 355 356def test_build_helpers_are_pinned_but_absent_from_runtime_install (self ): 357runtime = {setup .req_name (x )for x in setup .requirement_lines ()} 358build = setup .requirement_lines (setup .BUILD_REQUIREMENTS ) 359self .assertEqual ({setup .req_name (x )for x in build }, {"cmake" ,"ninja" }) 360self .assertTrue (all ("==" in x for x in build )) 361self .assertTrue (runtime .isdisjoint ({"cmake" ,"ninja" })) 362 363def test_local_build_installs_only_missing_helper (self ): 364installed = False 365requests = [] 366commands = [] 367 368def find_tool (name ): 369if name == "cmake" : 370return "/usr/bin/cmake" 371return "/venv/bin/ninja" if installed else None 372 373def pip_install (packages ,what ): 374nonlocal installed 375requests .append ((packages ,what )) 376installed = True 377 378def run (command ,** kwargs ): 379commands .append (command ) 380return mock .Mock (returncode = 0 ) 381 382with mock .patch .object (setup ,"WIN" ,False ), \ 383mock .patch .object (setup ,"find_tool" ,side_effect = find_tool ), \ 384mock .patch .object (setup ,"_tool_version" ,return_value = (True , (3 ,28 ,1 ))), \ 385mock .patch .object (setup ,"pip_install" ,side_effect = pip_install ), \ 386mock .patch .object (setup ,"run" ,side_effect = run ): 387setup .cmake_build (ROOT ,ROOT / "build-test" ,"strata" , [],None ,"unused.bat" ) 388self .assertEqual (requests , [(["ninja==1.13.2" ],"CMake and Ninja build tools" )]) 389self .assertEqual (commands [0 ][:4 ], ["/usr/bin/cmake" ,"-G" ,"Ninja" ,"-DCMAKE_MAKE_PROGRAM=/venv/bin/ninja" ]) 390self .assertEqual (commands [1 ][:3 ], ["/usr/bin/cmake" ,"--build" ,str (ROOT / "build-test" )]) 391 392def pip (self ,stamp ,packages ,installed = ()): 393ran = [] 394with tempfile .TemporaryDirectory ()as d : 395if stamp is not None : 396 (Path (d )/ ".strata-pip.json" ).write_text (json .dumps (stamp )) 397# written by this system (#3634's marker): without it the stamp is believed only when numpy/jinja2/regex/yaml import in the 398# Python running the tests, which made these tests depend on the box 399 (Path (d )/ ".strata-pip.json.os" ).write_text (setup .sys .platform ) 400with mock .patch .object (setup .sys ,"prefix" ,d ), \ 401mock .patch .object (setup ,"run" ,lambda cmd ,** kw :ran .append (cmd )), \ 402mock .patch .object (setup ,"_installed" ,lambda name :name in installed ): 403quiet (setup .pip_install ,packages ,"the packages" ) 404after = json .loads ((Path (d )/ ".strata-pip.json" ).read_text ())if ran else stamp 405return [c for cmd in ran for c in cmd if "==" in c or c in setup .PY_PACKAGES ],after 406 407def test_a_stamp_written_by_another_system_is_not_believed (self ):# #3634 408lines = setup .requirement_lines () 409with tempfile .TemporaryDirectory ()as d : 410 (Path (d )/ ".strata-pip.json" ).write_text (json .dumps (lines )) 411 (Path (d )/ ".strata-pip.json.os" ).write_text ("win32" if setup .sys .platform != "win32" else "linux" ) 412ran = [] 413with mock .patch .object (setup .sys ,"prefix" ,d ),mock .patch .object (setup ,"run" ,lambda cmd ,** kw :ran .append (cmd )): 414quiet (setup .pip_install ,lines ,"the packages" ) 415self .assertTrue (ran )# installed again, here 416self .assertEqual ((Path (d )/ ".strata-pip.json.os" ).read_text (),setup .sys .platform ) 417ran .clear () 418with mock .patch .object (setup .sys ,"prefix" ,d ),mock .patch .object (setup ,"run" ,lambda cmd ,** kw :ran .append (cmd )): 419quiet (setup .pip_install ,lines ,"the packages" ) 420self .assertFalse (ran )# and then skipped as before 421 422def test_fresh_install_gets_every_pin (self ): 423lines = setup .requirement_lines () 424ran ,stamp = self .pip (None ,lines ) 425self .assertEqual (ran ,lines ) 426self .assertEqual (sorted (stamp ),sorted (lines )) 427self .assertEqual (self .pip (stamp ,lines )[0 ], [])# the second run: nothing 428 429def test_an_install_from_before_the_pins_is_left_alone (self ): 430lines = setup .requirement_lines () 431legacy = sorted (setup .PY_PACKAGES )+ ["nvidia-cublas==13.0.2.14" ] 432deps = {"markupsafe" ,"certifi" ,"charset-normalizer" ,"idna" ,"urllib3" ,"colorama" } 433# the packages it has stay as they are; only truststore (#3722: the operating system's certificates) is new, and it is wanted 434self .assertEqual (self .pip (legacy ,lines ,installed = deps )[0 ], ['truststore==0.10.5; python_version >= "3.10"' ]) 435deps .add ("truststore" ) 436self .assertEqual (self .pip (legacy ,lines ,installed = deps )[0 ], []) 437missing = [p for p in legacy if p != "psutil" ]# an older list without psutil 438ran ,_ = self .pip (missing ,lines ,installed = deps ) 439self .assertEqual (ran , ["psutil==7.2.2" ]) 440 441def test_a_changed_pin_is_installed (self ): 442lines = setup .requirement_lines () 443old = [x .replace ("tqdm==4.70.1" ,"tqdm==4.60.0" )for x in lines ] 444ran ,_ = self .pip (old ,lines ) 445self .assertEqual (ran , ["tqdm==4.70.1" ]) 446 447 448if __name__ == "__main__" : 449unittest .main ()