otko/tests/gui/test_selection.py
smillmorel 61b850bf46
Some checks failed
CI / lint (pull_request) Has been cancelled
CI / type (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.12) (pull_request) Has been cancelled
CI / test-gui (pull_request) Has been cancelled
CI / test-integration (macos-latest) (pull_request) Has been cancelled
CI / test-integration (ubuntu-latest) (pull_request) Has been cancelled
CI / test-integration (windows-latest) (pull_request) Has been cancelled
style: resolve the remaining ruff findings
Auto-fixes (UP037, UP038, F401, I001, SIM105, RUF100) plus hand-fixes:
drop the now-unused `Union` imports, annotate mutable class attributes
with ClassVar, raise ValidationError instead of blind Exception in the
zero-length test, delete two dead locals, and bind the per-iteration
grid-builder closures to their loop variables (B023).
2026-09-16 13:20:36 -04:00

70 lines
1.9 KiB
Python

"""Unit tests for the SelectionState QObject."""
from __future__ import annotations
import pytest
pytest.importorskip("PySide6")
from otko.views.canvas3d import SelectionState
@pytest.mark.gui
def test_initial_state_is_empty(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
assert s.is_empty
assert s.nodes == frozenset()
assert s.elements == frozenset()
@pytest.mark.gui
def test_select_node_emits_signal(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
with qtbot.waitSignal(s.selectionChanged, timeout=500) as blocker:
s.select_node(7)
assert blocker.args[0] == frozenset({7})
assert blocker.args[1] == frozenset()
@pytest.mark.gui
def test_replacing_selection_clears_other_kind(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
s.select_node(1)
s.select_element(5)
assert s.nodes == frozenset()
assert s.elements == frozenset({5})
@pytest.mark.gui
def test_additive_selection_keeps_both(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
s.select_node(1)
s.select_node(2, additive=True)
assert s.nodes == frozenset({1, 2})
@pytest.mark.gui
def test_toggle_node(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
s.toggle_node(3)
assert 3 in s.nodes
s.toggle_node(3)
assert 3 not in s.nodes
@pytest.mark.gui
def test_clear_no_op_when_empty_does_not_emit(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
received: list[tuple] = []
s.selectionChanged.connect(lambda n, e: received.append((n, e)))
s.clear()
assert received == []
@pytest.mark.gui
def test_clear_emits_when_non_empty(qtbot) -> None: # type: ignore[no-untyped-def]
s = SelectionState()
s.select_node(1)
with qtbot.waitSignal(s.selectionChanged, timeout=500):
s.clear()
assert s.is_empty