70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
"""Smoke tests for AI outfit panel defaults (offscreen Qt)."""
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
|
|
|
|
import services.file_service as fs
|
|
from services.config_service import DEFAULT_CONFIG
|
|
|
|
|
|
class TestAiOutfitPanelDefaults(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = Path(tempfile.mkdtemp())
|
|
self._env = os.environ.get("CMBOT_DATA_DIR")
|
|
os.environ["CMBOT_DATA_DIR"] = str(self.tmp / "data")
|
|
self.app_dir = self.tmp / "app"
|
|
self.app_dir.mkdir(parents=True)
|
|
self._orig_get_app_dir = fs.get_app_dir
|
|
fs.get_app_dir = lambda: self.app_dir
|
|
self.app = self._app()
|
|
|
|
def tearDown(self):
|
|
fs.get_app_dir = self._orig_get_app_dir
|
|
if self._env is None:
|
|
os.environ.pop("CMBOT_DATA_DIR", None)
|
|
else:
|
|
os.environ["CMBOT_DATA_DIR"] = self._env
|
|
shutil.rmtree(str(self.tmp), ignore_errors=True)
|
|
|
|
def _app(self):
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
app = QApplication.instance()
|
|
if app is None:
|
|
app = QApplication([])
|
|
return app
|
|
|
|
def _panel(self):
|
|
from app.widgets.ai_outfit_panel import AiOutfitPanel
|
|
|
|
return AiOutfitPanel()
|
|
|
|
def test_empty_config_defaults_to_outfit_output_dir(self):
|
|
panel = self._panel()
|
|
cfg = dict(DEFAULT_CONFIG)
|
|
cfg["outfit_output_dir"] = ""
|
|
|
|
panel.apply_config(cfg)
|
|
|
|
self.assertEqual(Path(panel._output_edit.text()), self.app_dir / "穿搭图片")
|
|
|
|
def test_saved_outfit_output_dir_takes_precedence(self):
|
|
panel = self._panel()
|
|
saved = self.tmp / "custom-output"
|
|
cfg = dict(DEFAULT_CONFIG)
|
|
cfg["outfit_output_dir"] = str(saved)
|
|
|
|
panel.apply_config(cfg)
|
|
|
|
self.assertEqual(Path(panel._output_edit.text()), saved)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|