feat: 增加 Client Windows 打包基础 (#92)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
"""Client 打包目录和发布清单测试。"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from build_tools.launcher import app_executable, install_root
|
||||
from build_tools.release_manifest import MANIFEST_FILE_NAME, write_manifest
|
||||
from src.db import data_dir
|
||||
|
||||
|
||||
class LauncherPathTest(unittest.TestCase):
|
||||
def test_main_program_is_inside_app_directory(self):
|
||||
root = Path("D:/CMAutoBuy")
|
||||
self.assertEqual(
|
||||
app_executable(root),
|
||||
root / "app" / "CMAutoBuy.exe",
|
||||
)
|
||||
|
||||
def test_install_root_is_launcher_parent(self):
|
||||
self.assertEqual(
|
||||
install_root("D:/CMAutoBuy/Launcher.exe"),
|
||||
Path("D:/CMAutoBuy"),
|
||||
)
|
||||
|
||||
|
||||
class PackagedDataPathTest(unittest.TestCase):
|
||||
def test_packaged_main_program_uses_root_data_directory(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
executable = root / "app" / "CMAutoBuy.exe"
|
||||
with patch("src.db.sys.frozen", True, create=True), patch(
|
||||
"src.db.sys.executable", str(executable)
|
||||
):
|
||||
self.assertEqual(data_dir(), root / "data")
|
||||
|
||||
|
||||
class ReleaseManifestTest(unittest.TestCase):
|
||||
def test_manifest_name_and_hash_match_release_files(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
update_zip = root / "CMAutoBuy-0.1.0-update.zip"
|
||||
portable_zip = root / "CMAutoBuy-0.1.0-portable.zip"
|
||||
update_zip.write_bytes(b"update")
|
||||
portable_zip.write_bytes(b"portable")
|
||||
output = root / MANIFEST_FILE_NAME
|
||||
|
||||
write_manifest("0.1.0", update_zip, portable_zip, output)
|
||||
|
||||
self.assertEqual(output.name, "autobuy——manifest.json")
|
||||
manifest = json.loads(output.read_text(encoding="utf-8"))
|
||||
self.assertEqual(manifest["version"], "0.1.0")
|
||||
self.assertEqual(manifest["update"]["size"], len(b"update"))
|
||||
self.assertEqual(
|
||||
manifest["update"]["sha256"],
|
||||
hashlib.sha256(b"update").hexdigest(),
|
||||
)
|
||||
self.assertEqual(manifest["portable"]["file"], portable_zip.name)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user