From 3096f3856a182171187f05550d8b9214e3445dec Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 1 Apr 2015 20:50:20 -0300 Subject: [PATCH] Implemented test for TextBase widget --- .../mainwindow/statusbar/test_textbase.py | 46 +++++++++++++++++++ tox.ini | 2 + 2 files changed, 48 insertions(+) create mode 100644 qutebrowser/test/mainwindow/statusbar/test_textbase.py diff --git a/qutebrowser/test/mainwindow/statusbar/test_textbase.py b/qutebrowser/test/mainwindow/statusbar/test_textbase.py new file mode 100644 index 000000000..1c1082783 --- /dev/null +++ b/qutebrowser/test/mainwindow/statusbar/test_textbase.py @@ -0,0 +1,46 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2015 Florian Bruhin (The Compiler) +# +# 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 . + + +"""Test TextBase widget.""" + +from qutebrowser.mainwindow.statusbar.textbase import TextBase + + +def test_elided_text(qtbot): + """ + Ensure that a widget that can't hold the entire label text will display + and elided version of the string instead. + + Args: + qtbot: pytestqt.plugin.QtBot fixture + + 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. + """ + label = TextBase() + qtbot.add_widget(label) + long_string = 'Hello world! ' * 20 + label.setText(long_string) + label.resize(100, 50) + label.show() + assert '…' in label._elided_text diff --git a/tox.ini b/tox.ini index 3743eae91..994f2b089 100644 --- a/tox.ini +++ b/tox.ini @@ -19,6 +19,7 @@ setenv = QT_QPA_PLATFORM_PLUGIN_PATH={envsitepackagesdir}/PyQt5/plugins/platform deps = py==1.4.26 pytest==2.7.0 + pytest-qt==1.3.0 # We don't use {[testenv:mkvenv]commands} here because that seems to be broken # on Ubuntu Trusty. commands = @@ -30,6 +31,7 @@ deps = {[testenv:unittests]deps} coverage==3.7.1 pytest-cov==1.8.1 + pytest-qt==1.3.0 cov-core==1.15.0 commands = {[testenv:mkvenv]commands}