From e584aa319f9930047864f06f47d716e6ed8f5f22 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 4 Apr 2015 11:03:42 -0300 Subject: [PATCH] Using parametrization in test_textbase Also changed the wording a bit as suggested by @The-Compiler Conflicts: tests/mainwindow/statusbar/test_textbase.py --- tests/mainwindow/statusbar/test_textbase.py | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/mainwindow/statusbar/test_textbase.py b/tests/mainwindow/statusbar/test_textbase.py index 0abdf669b..eadf9c46a 100644 --- a/tests/mainwindow/statusbar/test_textbase.py +++ b/tests/mainwindow/statusbar/test_textbase.py @@ -19,25 +19,35 @@ """Test TextBase widget.""" +from PyQt5.QtCore import Qt +import pytest from qutebrowser.mainwindow.statusbar.textbase import TextBase -def test_elided_text(qtbot): +@pytest.mark.parametrize('elidemode, check', [ + (Qt.ElideRight, lambda s: s.endswith('…')), + (Qt.ElideLeft, lambda s: s.startswith('…')), + (Qt.ElideMiddle, lambda s: '…' in s), + (Qt.ElideNone, lambda s: '…' not in s), +]) +def test_elided_text(qtbot, elidemode, check): """Ensure that a widget too small to hold the entire label text will elide. - Note: - It is difficult to check what is actually being drawn in a portable - way, so at least we ensure our customized methods are being called and - the elided string contains the horizontal ellipsis character. + It is difficult to check what is actually being drawn in a portable way, so + at least we ensure our customized methods are being called and the elided + string contains the horizontal ellipsis character. Args: qtbot: pytestqt.plugin.QtBot fixture + elidemode: parametrized elide mode + check: function that receives the elided text and must return True + if the elipsis is placed correctly according to elidemode. """ - label = TextBase() + label = TextBase(elidemode=elidemode) qtbot.add_widget(label) long_string = 'Hello world! ' * 20 label.setText(long_string) label.resize(100, 50) label.show() - assert '…' in label._elided_text # pylint: disable=protected-access + assert check(label._elided_text) # pylint: disable=protected-access