okami.mom/strata

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

Niko1221Merge branch 'f-021-iE' into f-021-int3616148bb

main
2.3 KiB54 linesraw
1"""#3202: a Windows 11 with Russian localization (cp1251 / cp866 code pages): a Cyrillic folder name must reach the engine,
2the run config and the tools unchanged."""
3import json
4import os
5import subprocess
6import sys
7import tempfile
8import unittest
9from pathlib import Path
10
11ROOT = Path(__file__).resolve().parents[1]
12sys.path.insert(0, str(ROOT))
13
14WORD = "".join(chr(c) for c in (0x414, 0x43e, 0x43a, 0x443, 0x43c, 0x435, 0x43d, 0x442, 0x44b))   # "Документы"
15
16
17class CyrillicFolder(unittest.TestCase):
18    def setUp(self):
19        self.tmp = tempfile.TemporaryDirectory(prefix=WORD + "-")
20        self.dir = Path(self.tmp.name)
21
22    def tearDown(self):
23        self.tmp.cleanup()
24
25    def test_run_config_in_a_cyrillic_folder_is_found_and_read(self):
26        from strata_control import discovery
27        cfg = self.dir / "strata-q2_0.json"
28        cfg.write_text(json.dumps({"exe": "x", "args": ["--native", str(self.dir / "m.gguf")]}, ensure_ascii=False), encoding="utf-8")
29        place = discovery.places(explicit=self.dir)[0]
30        self.assertEqual(place.configs, 1)
31        back = json.loads(discovery.config_files(self.dir)[0].read_text(encoding="utf-8"))
32        self.assertIn(WORD, back["args"][1])
33
34    def test_a_child_python_gets_the_path_as_an_argument_and_prints_it_back(self):
35        # the server starts the engine through serve.server.popen; the child reads the argument and its own file listing
36        from serve import server
37        (self.dir / "m.gguf").write_bytes(b"x")
38        env = dict(os.environ, PYTHONUTF8="1", PYTHONIOENCODING="utf-8")
39        code = "import sys, os; print(sys.argv[1]); print(os.path.exists(os.path.join(sys.argv[1], 'm.gguf')))"
40        proc = server.popen("test child", [sys.executable, "-c", code, str(self.dir)], role="test",
41                            stdout=subprocess.PIPE, env=env)
42        out = proc.stdout.read().decode("utf-8").splitlines()
43        proc.wait(timeout=30)
44        self.assertEqual(out[0], str(self.dir))
45        self.assertEqual(out[1], "True")
46
47    def test_windows_launchers_set_utf8_mode(self):
48        for name in ("START-HERE.bat", "bin/strata.cmd", "bin/strata.ps1"):
49            text = (ROOT / name).read_text(encoding="utf-8")
50            self.assertIn("PYTHONUTF8", text, name)
51
52
53if __name__ == "__main__":
54    unittest.main()