Files
cmshoppe/tests/test_packaging.py
T

52 lines
1.6 KiB
Python
Raw Normal View History

2026-07-03 09:26:27 +08:00
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_keeps_program_and_data_paths_separate(self):
2026-07-03 09:26:27 +08:00
main_py = self.read_text("main.py")
gui_init = self.read_text("app/gui/__init__.py")
2026-07-03 09:26:27 +08:00
self.assertIn('getattr(sys, "frozen", False)', main_py)
self.assertIn("sys.executable", main_py)
self.assertNotIn("os.chdir(PROJECT_ROOT)", main_py)
self.assertIn("appconfig.prepare_data_dir()", gui_init)
2026-07-03 09:26:27 +08:00
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",
"data",
2026-07-03 09:26:27 +08:00
):
self.assertIn(token, script)
self.assertIn("python -m PyInstaller --noconfirm --clean", script)
self.assertIn("cmshopee.spec", script)
if __name__ == "__main__":
unittest.main()