add test for performance summary
+import dataclasses
import json
import os
import subprocess
import sys
from pathlib import Path
+from unittest.mock import MagicMock
+from napari._qt.perf import qt_performance
from napari._tests.utils import skip_local_popups, skip_on_win_ci
# NOTE:
@@ -55,3 +58,31 @@ def test_trace_on_start(tmp_path: Path):
for event in data:
for field in ['pid', 'tid', 'name', 'ph', 'ts', 'args']:
assert field in event
+
+
+def test_qt_performance(qtbot, monkeypatch):
+ widget = qt_performance.QtPerformance()
+ widget.timer.stop()
+ qtbot.addWidget(widget)
+ mock = MagicMock()
+ data = [
+ ("test1", MockTimer(1, 1)),
+ ("test2", MockTimer(20, 120)),
+ ("test1", MockTimer(70, 90)),
+ ("test2", MockTimer(50, 220)),
+ ]
+ mock.timers.items = MagicMock(return_value=data)
+ monkeypatch.setattr(qt_performance.perf, 'timers', mock)
+ assert widget.log.toPlainText() == ""
+ widget.update()
+ assert widget.log.toPlainText() == ' 120ms test2\n 220ms test2\n'
+ widget._change_thresh("150")
+ assert widget.log.toPlainText() == ""
+ widget.update()
+ assert widget.log.toPlainText() == ' 220ms test2\n'
+
+
+@dataclasses.dataclass
+class MockTimer:
+ average: float
+ max: float
