From 5a1663c584a5beccb38d68d3d895e9dc66c6aa18 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 12 Aug 2015 07:37:00 +0200 Subject: [PATCH] 100% coverage for mainwindow.statusbar.textbase. --- scripts/dev/check_coverage.py | 1 + tests/mainwindow/statusbar/test_textbase.py | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index fd94a39d6..d2b158bd7 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -48,6 +48,7 @@ PERFECT_FILES = [ 'qutebrowser/mainwindow/statusbar/percentage.py', 'qutebrowser/mainwindow/statusbar/progress.py', 'qutebrowser/mainwindow/statusbar/tabindex.py', + 'qutebrowser/mainwindow/statusbar/textbase.py', 'qutebrowser/config/configtypes.py', 'qutebrowser/config/configdata.py', diff --git a/tests/mainwindow/statusbar/test_textbase.py b/tests/mainwindow/statusbar/test_textbase.py index 94c502299..2a3f97c2d 100644 --- a/tests/mainwindow/statusbar/test_textbase.py +++ b/tests/mainwindow/statusbar/test_textbase.py @@ -50,4 +50,45 @@ def test_elided_text(qtbot, elidemode, check): label.setText(long_string) label.resize(100, 50) label.show() + qtbot.waitForWindowShown(label) assert check(label._elided_text) + + +def test_settext_empty(mocker, qtbot): + """Make sure using setText('') works and runs repaint.""" + label = TextBase() + qtbot.add_widget(label) + mocker.patch('qutebrowser.mainwindow.statusbar.textbase.TextBase.repaint', + autospec=True) + + label.setText('') + label.repaint.assert_called_with() + + +def test_resize(qtbot): + """Make sure the elided text is updated when resizing.""" + label = TextBase() + qtbot.add_widget(label) + long_string = 'Hello world! ' * 20 + label.setText(long_string) + + label.show() + qtbot.waitForWindowShown(label) + + text_1 = label._elided_text + label.resize(20, 50) + text_2 = label._elided_text + + assert text_1 != text_2 + + +def test_text_elide_none(mocker, qtbot): + """Make sure the text doesn't get elided if it's empty.""" + label = TextBase() + qtbot.add_widget(label) + label.setText('') + mocker.patch('qutebrowser.mainwindow.statusbar.textbase.TextBase.' + 'fontMetrics') + label._update_elided_text(20) + + assert not label.fontMetrics.called