okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b2de2641f
main
1"""#3269: a tool run by hand from the Control package finds gguf-py in the install folder setup.py wrote it to.""" 2import os 3import sys 4import tempfile 5import unittest 6from pathlib import Path 7from unittest import mock 8 9sys .path .insert (0 ,str (Path (__file__ ).resolve ().parent )) 10import _paths # noqa: E402 11 12 13class GgufPyLookup (unittest .TestCase ): 14def test_install_dir_is_searched (self ): 15with tempfile .TemporaryDirectory ()as d : 16gp = Path (d )/ "third_party" / "strata-gguf-py" 17 (gp / "gguf" ).mkdir (parents = True ) 18env = {k :v for k ,v in os .environ .items ()if k != "STRATA_GGUF_PY" } 19env ["STRATA_INSTALL_DIR" ]= d 20with mock .patch .dict (os .environ ,env ,clear = True ), \ 21mock .patch .object (_paths ,"ENGINE" ,Path (d )/ "nowhere" / "pkg" ): 22self .assertEqual (_paths .gguf_py (),str (gp )) 23 24def test_the_vendored_copy_is_found_without_any_download_or_setting (self ): 25"""OWN-1B: third_party/strata-gguf-py ships with the sources and the Terminal/Control packages.""" 26env = {k :v for k ,v in os .environ .items ()if k not in ("STRATA_GGUF_PY" ,"STRATA_INSTALL_DIR" )} 27with mock .patch .dict (os .environ ,env ,clear = True ),mock .patch .object (_paths ,"_install_dirs" ,return_value = []): 28self .assertEqual (Path (_paths .gguf_py ()),_paths .VENDORED ) 29self .assertTrue ((_paths .VENDORED / "gguf" / "__init__.py" ).is_file ()) 30self .assertTrue ((Path (_paths .converter_dir ())/ "convert_hf_to_gguf.py" ).is_file ()) 31self .assertTrue ((Path (_paths .converter_dir ())/ "conversion" / "qwen4exp.py" ).is_file ()) 32 33def test_env_wins_and_message_names_it (self ): 34with tempfile .TemporaryDirectory ()as d : 35 (Path (d )/ "gguf" ).mkdir () 36with mock .patch .dict (os .environ , {"STRATA_GGUF_PY" :d }): 37self .assertEqual (_paths .gguf_py (),d ) 38env = {k :v for k ,v in os .environ .items ()if k not in ("STRATA_GGUF_PY" ,"STRATA_INSTALL_DIR" )} 39with tempfile .TemporaryDirectory ()as d ,mock .patch .dict (os .environ ,env ,clear = True ), \ 40mock .patch .object (_paths ,"ENGINE" ,Path (d )/ "a" / "b" ), \ 41mock .patch .object (_paths ,"_install_dirs" ,return_value = []): 42with self .assertRaises (SystemExit )as cm : 43_paths .gguf_py () 44self .assertIn ("STRATA_GGUF_PY" ,str (cm .exception )) 45 46 47if __name__ == "__main__" : 48unittest .main ()