Skip to content

Commit 7d1dee2

Browse files
committed
Cover preview stop during camera startup
Update GUI preview tests to mock `is_active` alongside `is_running`, aligning with current controller-state checks. Adds a regression test for stopping preview while a camera is still starting (`is_active=True`, `is_running=False`) and verifies the expected shutdown order: recording, inference, then controller stop.
1 parent e1e8f93 commit 7d1dee2

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎tests/gui/main_window/test_preview.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_stop_preview_requests_orderly_shutdown(self, monkeypatch, window):
5656
calls: list[str] = []
5757

5858
monkeypatch.setattr(w.multi_camera_controller, "is_running", lambda: True)
59+
monkeypatch.setattr(w.multi_camera_controller, "is_active", lambda: True)
5960
monkeypatch.setattr(w, "_stop_multi_camera_recording", lambda: calls.append("recording"))
6061
monkeypatch.setattr(w, "_stop_inference", lambda show_message=False: calls.append("inference"))
6162
monkeypatch.setattr(

‎tests/gui/test_main.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def test_preview_renders_frames(
4545
def fake_is_running():
4646
return running
4747

48+
def fake_is_active():
49+
return running
50+
4851
def fake_get_active_count():
4952
return 1 if running else 0
5053

@@ -65,6 +68,7 @@ def fake_stop(*, wait=True):
6568
QTimer.singleShot(0, ctrl.all_stopped.emit)
6669

6770
monkeypatch.setattr(ctrl, "is_running", fake_is_running)
71+
monkeypatch.setattr(ctrl, "is_active", fake_is_active)
6872
monkeypatch.setattr(
6973
ctrl,
7074
"get_active_count",
@@ -96,6 +100,47 @@ def fake_stop(*, wait=True):
96100
assert w._current_frame is None
97101

98102

103+
def test_stop_preview_while_camera_is_starting(
104+
monkeypatch,
105+
window,
106+
):
107+
calls = []
108+
109+
monkeypatch.setattr(
110+
window.multi_camera_controller,
111+
"is_running",
112+
lambda: False,
113+
)
114+
monkeypatch.setattr(
115+
window.multi_camera_controller,
116+
"is_active",
117+
lambda: True,
118+
)
119+
monkeypatch.setattr(
120+
window.multi_camera_controller,
121+
"stop",
122+
lambda *args, **kwargs: calls.append("controller"),
123+
)
124+
monkeypatch.setattr(
125+
window,
126+
"_stop_multi_camera_recording",
127+
lambda: calls.append("recording"),
128+
)
129+
monkeypatch.setattr(
130+
window,
131+
"_stop_inference",
132+
lambda show_message=False: calls.append("inference"),
133+
)
134+
135+
window._stop_preview()
136+
137+
assert calls == [
138+
"recording",
139+
"inference",
140+
"controller",
141+
]
142+
143+
99144
@pytest.mark.gui
100145
@pytest.mark.functional
101146
def test_start_inference_emits_pose(qtbot, window, multi_camera_controller, dlc_processor, tmp_path):

0 commit comments

Comments
 (0)