feat: add outfit output directory
This commit is contained in:
@@ -185,7 +185,7 @@ class TestAiOutfitCore(unittest.TestCase):
|
||||
from core.ai_outfit import generate_outfit_image
|
||||
|
||||
d = self._make_dir_with_images("a")
|
||||
out = self.tmp / "out"
|
||||
out = self.tmp / "穿搭图片"
|
||||
client = _RecordingClient(self._image_bytes())
|
||||
|
||||
result = generate_outfit_image(
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
"""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()
|
||||
@@ -103,5 +103,63 @@ class TestGetOutputDir(unittest.TestCase):
|
||||
fs._is_dir_writable = orig
|
||||
|
||||
|
||||
class TestGetOutfitOutputDir(unittest.TestCase):
|
||||
"""get_outfit_output_dir() default location (docs/11 §9)."""
|
||||
|
||||
def setUp(self):
|
||||
import tempfile
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self._env = os.environ.get("CMBOT_DATA_DIR")
|
||||
self._frozen = getattr(sys, "frozen", None)
|
||||
os.environ["CMBOT_DATA_DIR"] = str(self.tmp / "data")
|
||||
if hasattr(sys, "frozen"):
|
||||
del sys.frozen
|
||||
self._orig_app_dir = fs.get_app_dir
|
||||
|
||||
def tearDown(self):
|
||||
import shutil
|
||||
fs.get_app_dir = self._orig_app_dir
|
||||
if self._env is None:
|
||||
os.environ.pop("CMBOT_DATA_DIR", None)
|
||||
else:
|
||||
os.environ["CMBOT_DATA_DIR"] = self._env
|
||||
if self._frozen is None:
|
||||
if hasattr(sys, "frozen"):
|
||||
del sys.frozen
|
||||
else:
|
||||
sys.frozen = self._frozen
|
||||
shutil.rmtree(str(self.tmp), ignore_errors=True)
|
||||
|
||||
def test_dev_uses_project_outfit_folder(self):
|
||||
app = self.tmp / "project"
|
||||
app.mkdir()
|
||||
fs.get_app_dir = lambda: app
|
||||
|
||||
self.assertEqual(fs.get_outfit_output_dir(), app / "穿搭图片")
|
||||
|
||||
def test_frozen_uses_install_root_outfit_folder(self):
|
||||
app = self.tmp / "install" / "app"
|
||||
app.mkdir(parents=True)
|
||||
fs.get_app_dir = lambda: app
|
||||
sys.frozen = True
|
||||
|
||||
self.assertEqual(fs.get_outfit_output_dir(), self.tmp / "install" / "穿搭图片")
|
||||
|
||||
def test_frozen_falls_back_when_not_writable(self):
|
||||
app = self.tmp / "install" / "app"
|
||||
app.mkdir(parents=True)
|
||||
fs.get_app_dir = lambda: app
|
||||
sys.frozen = True
|
||||
orig = fs._is_dir_writable
|
||||
fs._is_dir_writable = lambda p: False
|
||||
try:
|
||||
self.assertEqual(
|
||||
fs.get_outfit_output_dir(),
|
||||
Path(os.environ["CMBOT_DATA_DIR"]) / "output" / "穿搭图片",
|
||||
)
|
||||
finally:
|
||||
fs._is_dir_writable = orig
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user