45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Focused safeguards for the 40250/Longju locale merge."""
|
|
|
|
import importlib.util
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
SPEC = importlib.util.spec_from_file_location("build_zh_locale", Path(__file__).with_name("build_zh_locale.py"))
|
|
MODULE = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(MODULE)
|
|
|
|
|
|
class LocaleBuildTest(unittest.TestCase):
|
|
def test_preserves_40250_keys_formats_and_proto(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
en, zh, client, output = (root / name for name in ("en", "zh", "client", "out/Client"))
|
|
for path in (en, zh, client):
|
|
path.mkdir()
|
|
(en / "locale_game.txt").write_bytes(b"GOOD\tValue %d\tSA\nBAD\t%s at %d\tSA\nONLY_EN\tFallback\n")
|
|
(zh / "locale_game.txt").write_bytes("GOOD\t中文 %d\nBAD\t中文 %d 和 %s\n".encode("gbk"))
|
|
(en / "locale_interface.txt").write_bytes(b"ACCEPT\tAccept\n")
|
|
(zh / "locale_interface.txt").write_bytes("ACCEPT\t确定\n".encode("gbk"))
|
|
(en / "item_proto").write_bytes(b"40250-proto")
|
|
(zh / "item_proto").write_bytes(b"old-proto")
|
|
(client / "pack").mkdir()
|
|
|
|
report_path = MODULE.build(en, zh, output, client)
|
|
merged = (output / "locale/zh/locale_game.txt").read_bytes().decode("gbk")
|
|
self.assertIn("GOOD\t中文 %d\tSA", merged)
|
|
self.assertIn("BAD\t%s at %d\tSA", merged)
|
|
self.assertIn("ONLY_EN\tFallback", merged)
|
|
self.assertEqual((output / "locale/zh/item_proto").read_bytes(), b"40250-proto")
|
|
self.assertEqual((output / "locale.cfg").read_text(), "10002 936 zh\n")
|
|
self.assertTrue((output / "pack").is_symlink())
|
|
report = json.loads(report_path.read_text())
|
|
self.assertEqual(report["files"]["locale_game.txt"]["incompatible_format_keys"], ["BAD"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|