"""저장 위치 대화상자 — 못 쓰는 폴더를 고르면 진행을 막는지.""" from __future__ import annotations import os import pytest pytest.importorskip("PySide6") os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") from PySide6.QtWidgets import QApplication # noqa: E402 from livesub import storage # noqa: E402 from livesub.ui.data_location import DataLocationDialog # noqa: E402 @pytest.fixture(scope="session") def qapp(): app = QApplication.instance() or QApplication([]) yield app @pytest.fixture def os_dir(tmp_path, monkeypatch): base = tmp_path / "appdata" / "LiveSub" monkeypatch.setattr(storage, "_os_config_dir", lambda: base) return base def test_first_run_dialog_starts_on_the_default_folder(qapp, os_dir): dialog = DataLocationDialog(storage.default_data_dir(), first_run=True) try: assert dialog.selected() == os_dir assert dialog.ok_button.isEnabled() finally: dialog.deleteLater() def test_empty_path_blocks_confirmation(qapp, os_dir): dialog = DataLocationDialog(storage.default_data_dir(), first_run=True) try: dialog.path_edit.setText(" ") assert not dialog.ok_button.isEnabled() dialog.path_edit.setText(str(os_dir.parent / "elsewhere")) assert dialog.ok_button.isEnabled() finally: dialog.deleteLater() def test_change_dialog_blocks_a_subfolder_of_the_current_one(qapp, tmp_path): current = tmp_path / "current" current.mkdir() dialog = DataLocationDialog(current, first_run=False) try: dialog.path_edit.setText(str(current / "inside")) assert not dialog.ok_button.isEnabled() dialog.path_edit.setText(str(tmp_path / "other")) assert dialog.ok_button.isEnabled() finally: dialog.deleteLater()