okami.mom/strata

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

Niko1221setup: the low-RAM mode's copy of the experts is checked for room where it is written (the data folder's packs folder), and the refusal names that folder in the approved words instead of the model folder; test16904848b

main
4.1 KiB80 linesraw
1"""The disk-room check of setup's own-files path (QA 0213): the low-RAM mode's copy of the experts is measured where it is written (the data
2folder's packs folder), and the refusal names that folder, not the model folder of files that are already there.
3
4    python -m unittest tools.test_setup_disk_room
5"""
6from __future__ import annotations
7
8import os
9import sys
10import tempfile
11import unittest
12from pathlib import Path
13
14ROOT = Path(__file__).resolve().parents[1]
15sys.path.insert(0, str(ROOT))
16import setup  # noqa: E402
17
18APPROVED_HINT = ("Free some space, move Strata's data folder to a bigger drive (strata launch --data-dir), "
19                 "or set Low-RAM mode to Automatic to run without the copy.")
20
21
22class DiskRoom(unittest.TestCase):
23    def folders(self):
24        tmp = tempfile.TemporaryDirectory()
25        self.addCleanup(tmp.cleanup)
26        models = Path(tmp.name) / "own-model-folder"
27        pack = Path(tmp.name) / "data" / "packs" / "iq3_s"
28        models.mkdir(parents=True)
29        pack.parent.mkdir(parents=True)
30        return models, pack
31
32    def test_the_copy_of_the_experts_is_refused_in_the_words_the_owner_approved_and_names_the_packs_folder(self):
33        models, pack = self.folders()
34        problem = setup.disk_room_problem(models, pack, 1.0, 52.0, free=lambda _path: 22.0)   # the QA case: 22 GB free, the model files are already there
35        self.assertIsNotNone(problem)
36        message, hint = problem
37        self.assertEqual(message, f"not enough free disk space for the low-RAM copy of the experts in {pack}: it needs about 53 GB and 22 GB are free there.")
38        self.assertEqual(hint, APPROVED_HINT)
39        self.assertNotIn(str(models), message)            # the refusal no longer names the folder of the person's own model files
40
41    def test_the_copy_is_measured_on_the_packs_drive_not_on_the_model_drive(self):
42        models, pack = self.folders()
43        free = {models: 500.0, pack.parent: 22.0}
44        real_stat = os.stat
45
46        def other_device(path, *a, **k):                   # the packs folder sits on another drive than the model folder
47            result = real_stat(path, *a, **k)
48            if Path(path) == pack.parent:
49                return os.stat_result((result.st_mode, result.st_ino, result.st_dev + 1, *tuple(result)[3:]))
50            return result
51        from unittest import mock
52        with mock.patch.object(setup.os, "stat", other_device):
53            problem = setup.disk_room_problem(models, pack, 1.0, 52.0, free=lambda path: free[path])
54        self.assertIsNotNone(problem)
55        self.assertIn("low-RAM copy of the experts", problem[0])
56        self.assertIn("it needs about 52 GB and 22 GB are free there", problem[0])      # no other files on that drive: just the copy
57        # and the other way round: a roomy packs drive, a full model drive: the model folder's refusal
58        free = {models: 0.5, pack.parent: 500.0}
59        with mock.patch.object(setup.os, "stat", other_device):
60            problem = setup.disk_room_problem(models, pack, 1.0, 52.0, free=lambda path: free[path])
61        self.assertIsNotNone(problem)
62        self.assertIn(f"not enough free disk space in {models}", problem[0])
63
64    def test_enough_room_and_no_copy(self):
65        models, pack = self.folders()
66        self.assertIsNone(setup.disk_room_problem(models, pack, 1.0, 52.0, free=lambda _path: 200.0))
67        self.assertIsNone(setup.disk_room_problem(models, pack, 5.0, 0, free=lambda _path: 6.0))
68        message, _hint = setup.disk_room_problem(models, pack, 5.0, 0, free=lambda _path: 4.0)
69        self.assertTrue(message.startswith(f"not enough free disk space in {models}: need ~5 GB, 4 GB free"))     # a download that does not fit: the old sentence
70
71    def test_the_old_refusal_for_the_copy_is_gone_from_the_run_path(self):
72        source = (ROOT / "setup.py").read_text(encoding="utf-8")
73        run = source[source.index("copy_gb = MODELS[model]"):]
74        run = run[:run.index("if free_now < need:")]
75        self.assertIn("disk_room_problem(", run)
76        self.assertNotIn("not enough free disk space in {models_dir}", run)
77
78
79if __name__ == "__main__":
80    unittest.main()