diff options
author | Florian Bruhin <git@the-compiler.org> | 2015-08-18 20:19:02 +0200 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2015-08-18 20:19:02 +0200 |
commit | 2c5269acd62c78619c9ed7b07af1926158e43c2c (patch) | |
tree | 68343a86be43190e93bbe3db60a469227ceebe4d /tests/unit/misc/test_miscwidgets.py | |
parent | d3d999e041b5add7bd11537cb4868456b3668d77 (diff) | |
download | qutebrowser-2c5269acd62c78619c9ed7b07af1926158e43c2c.tar.gz qutebrowser-2c5269acd62c78619c9ed7b07af1926158e43c2c.zip |
Reorganize tests directory.
Diffstat (limited to 'tests/unit/misc/test_miscwidgets.py')
-rw-r--r-- | tests/unit/misc/test_miscwidgets.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/unit/misc/test_miscwidgets.py b/tests/unit/misc/test_miscwidgets.py new file mode 100644 index 000000000..bd316935f --- /dev/null +++ b/tests/unit/misc/test_miscwidgets.py @@ -0,0 +1,90 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org> +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. + +"""Test widgets in miscwidgets module.""" + +from unittest import mock +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import QApplication +import pytest + +from qutebrowser.misc.miscwidgets import CommandLineEdit + + +class TestCommandLineEdit: + + """Tests for CommandLineEdit widget.""" + + @pytest.yield_fixture + def cmd_edit(self, qtbot): + """Fixture to initialize a CommandLineEdit.""" + cmd_edit = CommandLineEdit(None) + cmd_edit.set_prompt(':') + qtbot.add_widget(cmd_edit) + assert cmd_edit.text() == '' + yield cmd_edit + + @pytest.fixture + def mock_clipboard(self, mocker): + """Fixture to mock QApplication.clipboard. + + Return: + The mocked QClipboard object. + """ + mocker.patch.object(QApplication, 'clipboard') + clipboard = mock.MagicMock() + clipboard.supportsSelection.return_value = True + QApplication.clipboard.return_value = clipboard + return clipboard + + def test_position(self, qtbot, cmd_edit): + """Test cursor position based on the prompt.""" + qtbot.keyClicks(cmd_edit, ':hello') + assert cmd_edit.text() == ':hello' + assert cmd_edit.cursorPosition() == len(':hello') + + cmd_edit.home(mark=True) + assert cmd_edit.cursorPosition() == len(':hello') + qtbot.keyClick(cmd_edit, Qt.Key_Delete) + assert cmd_edit.text() == ':' + qtbot.keyClick(cmd_edit, Qt.Key_Backspace) + assert cmd_edit.text() == ':' + + qtbot.keyClicks(cmd_edit, 'hey again') + assert cmd_edit.text() == ':hey again' + + def test_invalid_prompt(self, qtbot, cmd_edit): + """Test preventing of an invalid prompt being entered.""" + qtbot.keyClicks(cmd_edit, '$hello') + assert cmd_edit.text() == '' + + def test_clipboard_paste(self, qtbot, cmd_edit, mock_clipboard): + """Test pasting commands from clipboard.""" + mock_clipboard.text.return_value = ':command' + qtbot.keyClick(cmd_edit, Qt.Key_Insert, Qt.ShiftModifier) + assert cmd_edit.text() == ':command' + + mock_clipboard.text.return_value = ' param1' + qtbot.keyClick(cmd_edit, Qt.Key_Insert, Qt.ShiftModifier) + assert cmd_edit.text() == ':command param1' + + cmd_edit.clear() + mock_clipboard.text.return_value = '$ command' + qtbot.keyClick(cmd_edit, Qt.Key_Insert, Qt.ShiftModifier) + assert cmd_edit.text() == ':command param1' |