Files
live-app-translator/tests/test_glossary.py
EJClaw 8b36b244ff feat: LiveSub 2차 — 자막 on/off, 모니터·위치 선택, GPU 저부하, 게임 용어집
이름을 Hearo → LiveSub 로 변경. 말장난보다 하는 일이 바로 보이는 쪽이 낫다.

자막 on/off
- 전역 단축키 Ctrl+Alt+S (자막) / Ctrl+Alt+D (번역) — Windows RegisterHotKey +
  네이티브 이벤트 필터라 게임 창이 떠 있어도 동작. 다른 OS 에서는 no-op
- 단축키·체크박스·우클릭 메뉴가 모두 같은 경로를 타도록 통합

모니터 선택 + 디스코드식 배치
- placement.py: Qt 비의존 배치 계산 (모니터 목록 → 9분할 좌표)
- AnchorGrid 위젯으로 3x3 위치 선택, 드래그하면 자유 배치로 전환
- 모니터 구성이 바뀌어도 자막이 화면 밖으로 사라지지 않도록 클램프

GPU 저부하 모드 (기본 켜짐)
- 연산 정밀도 int8 강등, VRAM 상한 35%, 추론 후 60ms 양보,
  300초 무음 시 모델 언로드, 중간 결과 비활성
- 기본 티어를 균형(6GB) → 신속(4GB) 으로 하향
- 8GB GPU 기준 자막 2.8GB / 게임 5.2GB

게임 용어집 번들 (304개)
- 롤 74 · 발로란트 59 · 오버워치2 49 · FPS공통 46 · 마크 38 · 방송 38
- 체크박스로 켜고 끄며, 사용자가 직접 등록한 항목이 항상 우선

검증: pytest 91개 통과 (배치 14 + 팩 12 + UI 6 신규), ruff clean

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-09-21 17:49:26 +09:00

76 lines
2.1 KiB
Python

from livesub.models.glossary import Glossary, GlossaryEntry
def make() -> Glossary:
return Glossary(
[
GlossaryEntry("headshot", {"ko": "헤드샷"}),
GlossaryEntry("head", {"ko": "머리"}),
GlossaryEntry("Nexus", {"ko": "넥서스", "ja": "ネクサス"}),
]
)
def test_protect_and_restore_roundtrip():
g = make()
protected, repl = g.protect("Nice headshot on the Nexus", "ko")
assert "headshot" not in protected
assert "Nexus" not in protected
assert repl == ["헤드샷", "넥서스"]
# 번역 모델이 플레이스홀더를 그대로 통과시켰다고 가정
assert Glossary.restore(protected, repl) == "Nice 헤드샷 on the 넥서스"
def test_longest_match_wins():
"""'headshot'이 'head'에 먼저 잡아먹히면 안 된다."""
g = make()
_, repl = g.protect("headshot", "ko")
assert repl == ["헤드샷"]
def test_word_boundary_for_latin_terms():
g = make()
_, repl = g.protect("overheated", "ko")
assert repl == []
def test_missing_target_language_is_left_alone():
g = make()
protected, repl = g.protect("headshot", "ja")
assert protected == "headshot"
assert repl == []
def test_prompt_hint_only_includes_present_terms():
g = make()
hint = g.prompt_hint("push to the Nexus", "ko")
assert "Nexus -> 넥서스" in hint
assert "headshot" not in hint
assert g.prompt_hint("nothing here", "ko") == ""
def test_case_insensitive_by_default():
g = make()
_, repl = g.protect("NEXUS down", "ko")
assert repl == ["넥서스"]
def test_save_and_load(tmp_path):
path = tmp_path / "glossary.json"
make().save(path)
loaded = Glossary.load(path)
assert len(loaded) == 3
assert loaded.entries[2].target_for("ja") == "ネクサス"
def test_add_replaces_existing_entry():
g = make()
g.add(GlossaryEntry("Nexus", {"ko": "본진"}))
assert len(g) == 3
_, repl = g.protect("Nexus", "ko")
assert repl == ["본진"]
def test_restore_ignores_out_of_range_placeholder():
assert Glossary.restore("a ⟦5⟧ b", ["x"]) == "a b"