100% coverage for mainwindow.statusbar.percentage.

This commit is contained in:
Florian Bruhin 2015-08-02 01:45:19 +02:00
parent 43db9d4526
commit f21cffd9b8
2 changed files with 24 additions and 5 deletions

View File

@ -36,6 +36,7 @@ PERFECT_FILES = [
'qutebrowser/misc/readline.py', 'qutebrowser/misc/readline.py',
'qutebrowser/browser/tabhistory.py', 'qutebrowser/browser/tabhistory.py',
'qutebrowser/mainwindow/statusbar/keystring.py', 'qutebrowser/mainwindow/statusbar/keystring.py',
'qutebrowser/mainwindow/statusbar/percentage.py',
'qutebrowser/config/configtypes.py', 'qutebrowser/config/configtypes.py',
'qutebrowser/config/configdata.py', 'qutebrowser/config/configdata.py',

View File

@ -20,11 +20,24 @@
"""Test Percentage widget.""" """Test Percentage widget."""
import collections
import pytest import pytest
from qutebrowser.mainwindow.statusbar.percentage import Percentage from qutebrowser.mainwindow.statusbar.percentage import Percentage
FakeTab = collections.namedtuple('FakeTab', 'scroll_pos')
@pytest.fixture
def percentage(qtbot):
"""Fixture providing a Percentage widget."""
widget = Percentage()
qtbot.add_widget(widget)
return widget
@pytest.mark.parametrize('y, expected', [ @pytest.mark.parametrize('y, expected', [
(0, '[top]'), (0, '[top]'),
(100, '[bot]'), (100, '[bot]'),
@ -32,17 +45,22 @@ from qutebrowser.mainwindow.statusbar.percentage import Percentage
(25, '[25%]'), (25, '[25%]'),
(5, '[ 5%]'), (5, '[ 5%]'),
]) ])
def test_percentage_text(qtbot, y, expected): def test_percentage_text(percentage, y, expected):
""" """
Test text displayed by the widget based on the y position of a page. Test text displayed by the widget based on the y position of a page.
Args: Args:
qtbot: pytestqt.plugin.QtBot fixture
y: y position of the page as an int in the range [0, 100]. y: y position of the page as an int in the range [0, 100].
parametrized. parametrized.
expected: expected text given y position. parametrized. expected: expected text given y position. parametrized.
""" """
percentage = Percentage() percentage.set_perc(x=None, y=y)
qtbot.add_widget(percentage)
percentage.set_perc(None, y=y)
assert percentage.text() == expected assert percentage.text() == expected
def test_tab_change(percentage):
"""Make sure the percentage gets changed correctly when switching tabs."""
percentage.set_perc(x=None, y=10)
tab = FakeTab(20)
percentage.on_tab_changed(tab)
assert percentage.text() == '[20%]'