From 39b09f7822e36b57c20e0f48e27d59cc1830ba32 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 26 Mar 2017 15:03:03 +0200 Subject: [PATCH] Improve messageview hide code --- qutebrowser/mainwindow/messageview.py | 4 +-- tests/unit/mainwindow/test_messageview.py | 30 +++++++++-------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index 4a91276df..5c407b78b 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -133,7 +133,5 @@ class MessageView(QWidget): def mousePressEvent(self, e): """Clear messages when they are clicked on.""" - criteria = [Qt.LeftButton, Qt.MiddleButton, Qt.RightButton] - - if e.button() in criteria: + if e.button() in [Qt.LeftButton, Qt.MiddleButton, Qt.RightButton]: self.clear_messages() diff --git a/tests/unit/mainwindow/test_messageview.py b/tests/unit/mainwindow/test_messageview.py index 15160f45c..ba77f3a49 100644 --- a/tests/unit/mainwindow/test_messageview.py +++ b/tests/unit/mainwindow/test_messageview.py @@ -18,8 +18,6 @@ # along with qutebrowser. If not, see . import pytest - -from PyQt5.QtTest import QTest from PyQt5.QtCore import Qt from qutebrowser.mainwindow import messageview @@ -119,21 +117,15 @@ def test_replaced_messages(view, replace1, replace2, length): assert len(view._messages) == length -def test_click_messages(qtbot, view): +@pytest.mark.parametrize('button, count', [ + (Qt.LeftButton, 0), + (Qt.MiddleButton, 0), + (Qt.RightButton, 0), + (Qt.BackButton, 2), +]) +def test_click_messages(qtbot, view, button, count): """Messages should dissappear when we click on them.""" - view.show_message(usertypes.MessageLevel.info, 'test mouse left click') - QTest.mousePress(view, Qt.LeftButton) - assert not view._messages - - view.show_message(usertypes.MessageLevel.info, 'test mouse middle click') - QTest.mousePress(view, Qt.MiddleButton) - assert not view._messages - - view.show_message(usertypes.MessageLevel.info, 'test mouse right click') - QTest.mousePress(view, Qt.RightButton) - assert not view._messages - - # Test mouse back button - This shouldn't clear messages. - view.show_message(usertypes.MessageLevel.info, 'test mouse back button') - QTest.mousePress(view, Qt.BackButton) - assert len(view._messages) == 1 + view.show_message(usertypes.MessageLevel.info, 'test mouse click') + view.show_message(usertypes.MessageLevel.info, 'test mouse click 2') + qtbot.mousePress(view, button) + assert len(view._messages) == count