Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def write(self, data):

# 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)
Expand Down
15 changes: 15 additions & 0 deletions tests-unit/app_test/logger_test.py
Original file line number Diff line number Diff line change
@@ -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"
Loading