72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""Tests for consistent keyboard activation of push buttons."""
|
|
|
|
import pytest
|
|
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtTest import QTest
|
|
from PySide6.QtWidgets import QApplication, QCheckBox, QDialogButtonBox, QPushButton
|
|
|
|
from src.accessibility.button_keyboard import install_button_keyboard_support
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def app():
|
|
application = QApplication.instance() or QApplication([])
|
|
keyboardFilter = install_button_keyboard_support(application)
|
|
yield application
|
|
application.removeEventFilter(keyboardFilter)
|
|
|
|
|
|
@pytest.mark.parametrize("key", (Qt.Key_Return, Qt.Key_Enter))
|
|
def test_enter_activates_focused_push_button(app, key):
|
|
button = QPushButton("Clear selection")
|
|
clicks = []
|
|
button.clicked.connect(lambda: clicks.append(True))
|
|
button.show()
|
|
button.setFocus()
|
|
|
|
QTest.keyClick(button, key)
|
|
|
|
assert clicks == [True]
|
|
|
|
|
|
def test_enter_does_not_activate_disabled_push_button(app):
|
|
button = QPushButton("Clear play cue")
|
|
clicks = []
|
|
button.clicked.connect(lambda: clicks.append(True))
|
|
button.setEnabled(False)
|
|
|
|
QTest.keyClick(button, Qt.Key_Return)
|
|
|
|
assert clicks == []
|
|
|
|
|
|
def test_enter_activates_dialog_button_box_buttons(app):
|
|
buttonBox = QDialogButtonBox(QDialogButtonBox.Close)
|
|
closeButton = buttonBox.button(QDialogButtonBox.Close)
|
|
clicks = []
|
|
closeButton.clicked.connect(lambda: clicks.append(True))
|
|
|
|
QTest.keyClick(closeButton, Qt.Key_Return)
|
|
|
|
assert clicks == [True]
|
|
|
|
|
|
def test_modified_enter_is_not_treated_as_button_activation(app):
|
|
button = QPushButton("Clear selection")
|
|
clicks = []
|
|
button.clicked.connect(lambda: clicks.append(True))
|
|
|
|
QTest.keyClick(button, Qt.Key_Return, Qt.ControlModifier)
|
|
|
|
assert clicks == []
|
|
|
|
|
|
def test_enter_handling_is_limited_to_push_buttons(app):
|
|
checkbox = QCheckBox("Select")
|
|
checkbox.setChecked(False)
|
|
|
|
QTest.keyClick(checkbox, Qt.Key_Return)
|
|
|
|
assert not checkbox.isChecked()
|