Files
live-app-translator/tests/test_ui_smoke.py
EJClaw 42a38eb938
Some checks failed
Windows / verify (push) Has been cancelled
fix: 아무 말도 없는데 "Okay." 자막이 계속 뜨던 것 · 전체 로그 탭 추가
Silero 가 버린 구간을 VAD 없이 다시 받을 때 직전 문장을 prompt 로 넘겼다.
말소리가 없으면 Whisper 는 prompt 를 그대로 따라 적어서, 한 번 "Okay." 가
나오면 그 뒤 잡음마다 "Okay." 가 나왔다 (turbo, 잡음 11종 모두). 다시 받을
때는 prompt 를 넘기지 않고, prompt 없이도 잡음에서 나오는 상투 환각
("Obrigado." "you" "Thank you." 등)은 버린다. 수정 후 같은 잡음 22건 중
자막이 나온 것 0건.

로그 탭: 실행 중 로그 전체를 메모리에 모아 보여주고 복사·파일 저장을
지원한다. 확정 자막마다 원문·번역·확률을, VAD 없이 다시 받은 구간은 채택/
버림 결과를 INFO 로 남겨 엉뚱한 자막의 원인을 로그로 볼 수 있게 했다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:36:27 +09:00

209 lines
7.1 KiB
Python

"""UI가 실제로 만들어지고 자막이 그려지는지 확인한다 (offscreen 렌더링)."""
from __future__ import annotations
import os
import pytest
pytest.importorskip("PySide6")
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from PySide6.QtGui import QImage, QPainter # noqa: E402
from PySide6.QtWidgets import QApplication # noqa: E402
from livesub.config import AppConfig # noqa: E402
from livesub.core.events import EngineState, EngineStatus, TranslationLine # noqa: E402
from livesub.models import ModelManager # noqa: E402
from livesub.ui.main_window import MainWindow # noqa: E402
from livesub.ui.overlay import paint_subtitle # noqa: E402
from livesub.ui.placement import ANCHOR_CUSTOM, list_screens, resolve_rect # noqa: E402
@pytest.fixture(scope="session")
def qapp():
app = QApplication.instance() or QApplication([])
yield app
@pytest.fixture
def window(qapp, tmp_path, monkeypatch):
monkeypatch.setattr("livesub.constants.user_data_dir", lambda: tmp_path)
config = AppConfig()
config.models.preload_on_start = False
config.glossary.path = str(tmp_path / "glossary.json")
win = MainWindow(config)
yield win
win.engine.shutdown()
win.overlay.close()
win.close()
def test_main_window_builds_all_pages(window):
assert window.stack.count() == 6
def test_navigation_switches_pages(window):
for index in range(6):
window._goto_page(index)
assert window.stack.currentIndex() == index
def test_status_updates_toggle_button(window):
window._on_status(EngineStatus(EngineState.RUNNING, "듣는 중"))
assert window.home_page.toggle_button.text() == "번역 정지"
window._on_status(EngineStatus(EngineState.IDLE, "대기 중"))
assert window.home_page.toggle_button.text() == "번역 시작"
def test_final_line_reaches_overlay_and_log(window):
window.config.log_transcripts = False
window._on_line(
TranslationLine("hello", "안녕하세요", "en", "ko", is_final=True, latency_s=1.2)
)
assert window.overlay._final_text == "안녕하세요"
assert window.home_page.log_list.count() == 1
def test_partial_line_is_not_logged(window):
window.config.log_transcripts = False
window._on_line(TranslationLine("hel", "", "en", "ko", is_final=False))
assert window.home_page.log_list.count() == 0
def test_log_page_shows_and_exports_app_logs(window, qapp, tmp_path):
"""엔진 스레드에서 남긴 로그가 로그 화면에 뜨고, 복사·저장 내용에 들어간다."""
import logging
import threading
from livesub.app import setup_logging
setup_logging(to_file=False)
worker = threading.Thread(
target=lambda: logging.getLogger("livesub.core.engine").warning("구간 처리 실패: 테스트")
)
worker.start()
worker.join()
qapp.processEvents()
page = window.log_page
assert "구간 처리 실패: 테스트" in page.view.toPlainText()
page.copy_to_clipboard()
copied = qapp.clipboard().text()
assert copied.startswith("LiveSub v")
assert "구간 처리 실패: 테스트" in copied
out = tmp_path / "log.txt"
page.save_to(str(out))
assert "구간 처리 실패: 테스트" in out.read_text(encoding="utf-8")
def test_tier_selection_updates_config(window):
window.models_page._on_tier_selected(window.models_page._cards[3].tier)
assert window.config.models.tier == "precision"
def test_subtitle_style_edit_propagates(window):
window.subtitle_page.size_spin.setValue(60)
assert window.config.subtitle.font_size == 60
def test_subtitle_toggle_turns_overlay_on_and_off(window):
"""자막 on/off — 단축키와 체크박스가 같은 경로를 탄다."""
window.config.overlay.visible = True
window.overlay.set_subtitle_visible(True)
window.toggle_subtitle()
assert window.config.overlay.visible is False
assert window.overlay.isVisible() is False
# 체크박스가 따라와야 한다 (시그널 연결 확인)
assert window.subtitle_page.overlay_check.isChecked() is False
window.toggle_subtitle()
assert window.config.overlay.visible is True
assert window.subtitle_page.overlay_check.isChecked() is True
def test_turning_subtitle_off_clears_leftover_text(window):
window.config.log_transcripts = False
window.overlay.set_subtitle_visible(True)
window._on_line(TranslationLine("hello", "안녕", "en", "ko", is_final=True))
assert window.overlay._final_text
window.toggle_subtitle()
assert window.overlay._final_text == ""
def test_checkbox_and_hotkey_do_not_fight_each_other(window):
"""체크박스 → 오버레이 → 체크박스 되먹임이 무한루프가 되면 안 된다."""
window.config.overlay.visible = True
window.overlay.set_subtitle_visible(True)
window.subtitle_page.overlay_check.setChecked(False)
assert window.config.overlay.visible is False
assert window.overlay.isVisible() is False
def test_anchor_selection_moves_the_overlay(window):
window.subtitle_page._on_anchor_selected("top-left")
assert window.config.overlay.anchor == "top-left"
screens = list_screens()
if screens: # offscreen 플랫폼에도 가상 화면이 하나 있다
expected = resolve_rect(
screens[0], "top-left",
window.config.overlay.width, window.config.overlay.height,
window.config.overlay.margin,
)
assert (window.config.overlay.x, window.config.overlay.y) == expected[:2]
def test_dragging_switches_to_custom_placement(window):
window.subtitle_page._on_anchor_selected("bottom-center")
assert window.config.overlay.anchor == "bottom-center"
window.overlay.move(123, 456)
window.overlay._drag_from = window.overlay.pos()
window.overlay.mouseReleaseEvent(None)
assert window.config.overlay.anchor == ANCHOR_CUSTOM
def test_glossary_packs_reach_the_engine(window):
window.config.glossary.enabled_packs = ["lol"]
window._on_glossary_changed()
_, repl = window.engine.glossary.protect("the Nexus", "ko")
assert repl == ["넥서스"]
def test_game_mode_lowers_precision(window):
window.config.performance.game_mode = True
manager = ModelManager(window.config.models, low_power=True)
assert "int8" in manager.effective_asr_spec().compute_type
assert manager.effective_asr_spec().beam_size == 1
normal = ModelManager(window.config.models, low_power=False)
assert normal.effective_asr_spec() == normal.tier.asr
def test_paint_subtitle_actually_draws_pixels(qapp):
"""자막 글씨가 투명 이미지 위에 실제로 그려지는지 (빈 화면이면 실패).
배경 상자가 픽셀을 채워버리면 글씨 유무를 알 수 없으므로 배경은 끄고 잰다.
"""
st = AppConfig().subtitle
st.background_opacity = 0
image = QImage(900, 200, QImage.Format.Format_ARGB32)
image.fill(0)
painter = QPainter(image)
paint_subtitle(painter, image.rect(), st, "안녕하세요 반갑습니다", "Hello there")
painter.end()
non_transparent = sum(
1
for y in range(0, image.height(), 4)
for x in range(0, image.width(), 4)
if image.pixelColor(x, y).alpha() > 0
)
assert non_transparent > 100