"""Review of the rail's unified play control: play/pause, stop, reset — and nothing else. Written against the requirement rather than the implementation: * the play-control group is exactly **play/pause**, **stop**, **reset** (no extra pause button, no role switch that turns the third button into a stop); * the primary button is a play/pause toggle in **both** views, and pressing it while a session runs pauses without stopping — the device stays connected; * stop ends the session (live) or leaves the replay (playback); * reset is disabled in the replay view, where there is no tracker to zero. """ from __future__ import annotations import ui_check from tests.conftest import finish_run, running_window, show_window def test_the_group_is_exactly_play_pause_stop_reset(make_window): window = show_window(make_window(sensor_type="box", source_mode="camera"), (1440, 880)) toolbar = window.toolbar assert not hasattr(toolbar, "btn_pause"), "an extra pause button is still in the rail" assert hasattr(toolbar, "btn_stop"), "there is no dedicated stop button" assert not hasattr(toolbar, "set_reset_role"), ( "the reset button still switches role to stop; one control cannot be two" ) assert toolbar.btn_run.isCheckable(), "the play/pause control must be a toggle" window.close() def test_the_primary_button_pauses_and_does_not_stop(make_window): """The heart of the unification: one toggle, three states, and stop is not the toggle.""" window, stuck = running_window(make_window) try: assert window._session_active, "the fixture did not start a session" assert window.toolbar.btn_run.isChecked(), ( "a running session must show the transport as engaged (pause available)" ) assert "暂停" in window.toolbar.btn_run.text() or "Paus" in window.toolbar.btn_run.text(), ( f"a running session reads {window.toolbar.btn_run.text()!r}, not pause" ) # Press it: pause, not stop. window.toolbar.btn_run.setChecked(False) assert window._session_active, "pressing the transport ended the session" assert window._display_paused is True, "the window did not record the pause" assert stuck.is_paused is True, "the worker was not paused" assert "继续" in window.toolbar.btn_run.text() or "Resume" in window.toolbar.btn_run.text(), ( f"a paused session reads {window.toolbar.btn_run.text()!r}, not resume" ) # Press it again: resume. window.toolbar.btn_run.setChecked(True) assert window._display_paused is False assert stuck.is_paused is False, "the worker was not resumed" assert window._session_active, "resuming ended the session" finally: finish_run(window, stuck) def test_stop_ends_the_session(make_window): window, stuck = running_window(make_window) try: # A first frame is what makes the session a *running* one (the rail's reset and # the phase both key off it), so drive one before pressing stop. stuck.emit(ui_check._fake_packet(1)) window._on_run_tick() assert window.toolbar.btn_stop.isEnabled(), "stop is not reachable while running" window.toolbar.btn_stop.click() assert window._session_phase != "running", ( f"the stop button left the session in {window._session_phase!r}" ) assert not window.toolbar.btn_run.isChecked(), "the transport stayed engaged after stop" assert window._display_paused is False, "the pause flag survived the stop" finally: stuck.release() def test_reset_is_for_the_device_and_is_disabled_in_the_replay_view(make_window): """Reset stays a *device* control, and it is the thing the replay view cannot offer. The enabled state of reset once frames are flowing is covered by ``test_ui_smoke.py::test_a_reset_reaches_the_device_and_is_recorded`` (which drives ``_on_reset``); this test pins what the unification is about: reset and stop are two different controls, and the replay view disables the one that needs a device. """ window, stuck = running_window(make_window) try: assert window.toolbar.btn_reset.text() != window.toolbar.btn_stop.text(), ( "reset and stop must be distinguishable controls" ) assert window.toolbar.btn_stop.isEnabled(), "stop is not reachable during a session" finally: finish_run(window, stuck) replay = show_window(make_window(sensor_type="box", source_mode="camera"), (1440, 880)) replay.brand_bar.btn_playback.click() assert not replay.toolbar.btn_reset.isEnabled(), ( "reset is offered in the replay view, where there is no tracker to zero" ) assert hasattr(replay.toolbar, "btn_stop"), "the replay view has no stop control" assert replay.toolbar.btn_run.text().startswith("▶"), ( f"the replay transport idle reads {replay.toolbar.btn_run.text()!r}, not play" ) replay.close()