Files
cmshoppe/tests/test_packaging.py
T
chengma 6d4f60fcdb
Tests / Python 3.11 / Windows (push) Has been cancelled
build: add pyinstaller packaging
2026-07-03 09:26:27 +08:00

49 lines
1.4 KiB
Python

import unittest
from _helpers import REPO_ROOT
class PackagingTests(unittest.TestCase):
def read_text(self, relative_path):
return (REPO_ROOT / relative_path).read_text(encoding="utf-8")
def test_frozen_entrypoint_uses_exe_directory(self):
main_py = self.read_text("main.py")
self.assertIn('getattr(sys, "frozen", False)', main_py)
self.assertIn("sys.executable", main_py)
self.assertIn("os.chdir(PROJECT_ROOT)", main_py)
def test_pyinstaller_spec_uses_onedir_without_local_datas(self):
spec = self.read_text("cmshopee.spec")
normalized = "".join(spec.split())
self.assertIn("datas=[]", normalized)
self.assertIn("COLLECT(", spec)
self.assertIn('name="cmshopee"', normalized)
def test_build_script_blocks_user_data_in_release_output(self):
script = self.read_text("scripts/build_exe.ps1")
for token in (
"config.json",
"config\\ai_models.json",
"cmshopee.db",
"cmshopee.db-wal",
"cmshopee.db-shm",
"db.sqlite",
"chrome_user_data_dir",
"images",
"logs",
"prompts",
"title_prompt.txt",
):
self.assertIn(token, script)
self.assertIn("python -m PyInstaller --noconfirm --clean", script)
self.assertIn("cmshopee.spec", script)
if __name__ == "__main__":
unittest.main()