Files
AareDAQ/tests/unit/gui/test_title_label.py
T
duan_jandClaude Fable 5 ce0ed20d5a style: fix lint for the banner/adaptive changes
- ruff format and import ordering (main_window, data_collection_settings,
  beam_center_panel, beamline_state_panel)
- rename unused unpacked variable in test_title_label
- replace the mousePressEvent monkeypatch on the beamline state title
  with a proper eventFilter so basedpyright accepts the diff

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 10:35:46 +02:00

73 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from PySide6.QtCore import QSettings
from PySide6.QtWidgets import QGridLayout, QHBoxLayout, QPushButton, QWidget
from aare.gui.widgets.title_label import TitleLabel
# Unique title so the test never clashes with real panel settings.
TITLE = "TitleLabelTestPanel"
KEY = f"panel_collapsed/{TITLE}"
def _remove_key():
QSettings("PSI", "AareGUI").remove(KEY)
def _build_panel(qtbot):
panel = QWidget()
qtbot.addWidget(panel)
grid = QGridLayout(panel)
title = TitleLabel(TITLE, panel, collapsible=True)
grid.addWidget(title, 0, 0, 1, 2)
direct_child = QPushButton("direct", panel)
grid.addWidget(direct_child, 1, 0)
nested = QHBoxLayout()
nested_child = QPushButton("nested", panel)
nested.addWidget(nested_child)
grid.addLayout(nested, 1, 1)
return panel, title, direct_child, nested_child
def test_toggle_hides_children_and_persists(qtbot):
_remove_key()
try:
panel, title, direct_child, nested_child = _build_panel(qtbot)
expanded_height = panel.sizeHint().height()
title.toggle_collapsed()
assert direct_child.isHidden()
assert nested_child.isHidden()
assert not title.isHidden()
assert panel.sizeHint().height() < expanded_height
assert title.toggle_button.text() == "+"
assert QSettings("PSI", "AareGUI").value(KEY, False, type=bool) is True
title.toggle_collapsed()
assert not direct_child.isHidden()
assert not nested_child.isHidden()
assert title.toggle_button.text() == ""
assert QSettings("PSI", "AareGUI").value(KEY, False, type=bool) is False
finally:
_remove_key()
def test_collapsed_state_restored_on_construction(qtbot):
QSettings("PSI", "AareGUI").setValue(KEY, True)
try:
_panel, title, direct_child, nested_child = _build_panel(qtbot)
# Restore is deferred with a 0 ms timer (siblings don't exist yet at
# TitleLabel construction), so let the event loop run once.
qtbot.waitUntil(lambda: direct_child.isHidden(), timeout=1000)
assert nested_child.isHidden()
assert title.toggle_button.text() == "+"
finally:
_remove_key()
def test_not_collapsible_by_default(qtbot):
panel = QWidget()
qtbot.addWidget(panel)
grid = QGridLayout(panel)
title = TitleLabel("Plain", panel)
grid.addWidget(title, 0, 0)
assert not hasattr(title, "toggle_button")