okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-1b (033cfdd8c) into f-own-int: nothing downloads llama.cppb2de2641f

main
2.4 KiB48 linesraw
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):
14    def test_install_dir_is_searched(self):
15        with tempfile.TemporaryDirectory() as d:
16            gp = Path(d) / "third_party" / "strata-gguf-py"
17            (gp / "gguf").mkdir(parents=True)
18            env = {k: v for k, v in os.environ.items() if k != "STRATA_GGUF_PY"}
19            env["STRATA_INSTALL_DIR"] = d
20            with mock.patch.dict(os.environ, env, clear=True), \
21                    mock.patch.object(_paths, "ENGINE", Path(d) / "nowhere" / "pkg"):
22                self.assertEqual(_paths.gguf_py(), str(gp))
23
24    def 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."""
26        env = {k: v for k, v in os.environ.items() if k not in ("STRATA_GGUF_PY", "STRATA_INSTALL_DIR")}
27        with mock.patch.dict(os.environ, env, clear=True), mock.patch.object(_paths, "_install_dirs", return_value=[]):
28            self.assertEqual(Path(_paths.gguf_py()), _paths.VENDORED)
29            self.assertTrue((_paths.VENDORED / "gguf" / "__init__.py").is_file())
30            self.assertTrue((Path(_paths.converter_dir()) / "convert_hf_to_gguf.py").is_file())
31            self.assertTrue((Path(_paths.converter_dir()) / "conversion" / "qwen4exp.py").is_file())
32
33    def test_env_wins_and_message_names_it(self):
34        with tempfile.TemporaryDirectory() as d:
35            (Path(d) / "gguf").mkdir()
36            with mock.patch.dict(os.environ, {"STRATA_GGUF_PY": d}):
37                self.assertEqual(_paths.gguf_py(), d)
38        env = {k: v for k, v in os.environ.items() if k not in ("STRATA_GGUF_PY", "STRATA_INSTALL_DIR")}
39        with tempfile.TemporaryDirectory() as d, mock.patch.dict(os.environ, env, clear=True), \
40                mock.patch.object(_paths, "ENGINE", Path(d) / "a" / "b"), \
41                mock.patch.object(_paths, "_install_dirs", return_value=[]):
42            with self.assertRaises(SystemExit) as cm:
43                _paths.gguf_py()
44            self.assertIn("STRATA_GGUF_PY", str(cm.exception))
45
46
47if __name__ == "__main__":
48    unittest.main()