some fixes
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
"""Unit tests for the bounded GUI log-panel buffer.
|
||||
|
||||
The buffer decouples logging handlers (any thread, potentially very chatty at
|
||||
DEBUG) from the GUI: records are batched by a flush timer instead of posting one
|
||||
queued Qt event per record, and overflow drops the oldest records with a count.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from python_app.gui.app_window import _PanelLogBuffer
|
||||
|
||||
|
||||
class PanelLogBufferTest(unittest.TestCase):
|
||||
"""Bounded capacity, oldest-first eviction, and accurate drop accounting."""
|
||||
|
||||
def test_drain_returns_entries_in_order_and_clears(self) -> None:
|
||||
buffer = _PanelLogBuffer()
|
||||
buffer.append("INFO", "first", None, None)
|
||||
buffer.append("WARN", "second", "details", "key")
|
||||
|
||||
entries, dropped_count = buffer.drain()
|
||||
|
||||
self.assertEqual(dropped_count, 0)
|
||||
self.assertEqual(
|
||||
entries,
|
||||
[("INFO", "first", None, None), ("WARN", "second", "details", "key")],
|
||||
)
|
||||
self.assertEqual(buffer.drain(), ([], 0))
|
||||
|
||||
def test_overflow_drops_oldest_and_counts(self) -> None:
|
||||
buffer = _PanelLogBuffer()
|
||||
overflow = 100
|
||||
total = _PanelLogBuffer._CAPACITY + overflow
|
||||
for index in range(total):
|
||||
buffer.append("DEBUG", f"m{index}", None, None)
|
||||
|
||||
entries, dropped_count = buffer.drain()
|
||||
|
||||
self.assertEqual(dropped_count, overflow)
|
||||
self.assertEqual(len(entries), _PanelLogBuffer._CAPACITY)
|
||||
self.assertEqual(entries[0][1], f"m{overflow}")
|
||||
self.assertEqual(entries[-1][1], f"m{total - 1}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user