49 lines
1.4 KiB
Python
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()
|