This commit is contained in:
medimedi 2026-08-15 20:51:43 +02:00 committed by GitHub
commit 95d93e7ed8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -64,7 +64,7 @@ class LogInterceptor(io.TextIOWrapper):
# Simple handling for cr to overwrite the last output if it isnt a full line
# else logs just get full of progress messages
if isinstance(data, str) and data.startswith("\r") and not logs[-1]["m"].endswith("\n"):
if isinstance(data, str) and data.startswith("\r") and logs and not logs[-1]["m"].endswith("\n"):
logs.pop()
logs.append(entry)
super().write(data)

View File

@ -0,0 +1,15 @@
from collections import deque
import io
import app.logger
def test_carriage_return_can_be_first_log_entry(monkeypatch):
monkeypatch.setattr(app.logger, "logs", deque())
stream = io.TextIOWrapper(io.BytesIO(), encoding="utf-8")
interceptor = app.logger.LogInterceptor(stream)
interceptor.write("\rprogress")
assert len(app.logger.logs) == 1
assert app.logger.logs[0]["m"] == "\rprogress"