Some checks failed
Windows / verify (push) Has been cancelled
화면은 최근 5000줄만 들고 있는데 복사·저장도 그 버퍼를 썼다. 오래 켜 두면 원인 찾기에 가장 필요한 시작 부분(GPU 준비·모델 로드)이 내보낸 로그에서 빠졌다. 내보내기는 이번 실행이 livesub.log 에 쓴 부분을 파일에서 다시 읽고, 저장 위치를 고르기 전의 줄을 앞에 붙인다. 파일을 못 쓰는 환경에서만 화면 버퍼로 돌아간다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""'로그' 화면의 복사·저장이 화면 줄 수 제한과 상관없이 이번 실행 기록 전체를 담는지."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
|
|
import livesub.app as app
|
|
from livesub.log_buffer import LogBuffer
|
|
|
|
|
|
@pytest.fixture
|
|
def small_buffer(tmp_path, monkeypatch):
|
|
buffer = LogBuffer(limit=3)
|
|
monkeypatch.setattr(app, "BUFFER", buffer)
|
|
monkeypatch.setattr(app, "user_data_dir", lambda: tmp_path)
|
|
yield buffer
|
|
root = logging.getLogger()
|
|
for handler in list(root.handlers):
|
|
root.removeHandler(handler)
|
|
handler.close()
|
|
|
|
|
|
def test_export_keeps_whole_run_beyond_screen_limit(small_buffer, tmp_path):
|
|
(tmp_path / "livesub.log").write_text("지난 실행 기록\n", encoding="utf-8")
|
|
log = logging.getLogger("livesub.test")
|
|
|
|
app.setup_logging(to_file=False) # 저장 위치를 고르기 전
|
|
log.info("저장 위치 고르기 전")
|
|
app.setup_logging()
|
|
for i in range(10):
|
|
log.info("줄 %d", i)
|
|
|
|
assert len(small_buffer.lines()) == 3 # 화면은 최근 것만
|
|
exported = small_buffer.full_text()
|
|
assert "저장 위치 고르기 전" in exported
|
|
assert all(f"줄 {i}" in exported for i in range(10))
|
|
assert "지난 실행 기록" not in exported
|
|
|
|
|
|
def test_export_falls_back_to_screen_lines_without_log_file(small_buffer):
|
|
app.setup_logging(to_file=False)
|
|
logging.getLogger("livesub.test").warning("파일 없음")
|
|
assert "파일 없음" in small_buffer.full_text()
|