100% coverage for mainwindow.statusbar.percentage.
This commit is contained in:
parent
43db9d4526
commit
f21cffd9b8
@ -36,6 +36,7 @@ PERFECT_FILES = [
|
||||
'qutebrowser/misc/readline.py',
|
||||
'qutebrowser/browser/tabhistory.py',
|
||||
'qutebrowser/mainwindow/statusbar/keystring.py',
|
||||
'qutebrowser/mainwindow/statusbar/percentage.py',
|
||||
|
||||
'qutebrowser/config/configtypes.py',
|
||||
'qutebrowser/config/configdata.py',
|
||||
|
@ -20,11 +20,24 @@
|
||||
|
||||
"""Test Percentage widget."""
|
||||
|
||||
import collections
|
||||
|
||||
import pytest
|
||||
|
||||
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', [
|
||||
(0, '[top]'),
|
||||
(100, '[bot]'),
|
||||
@ -32,17 +45,22 @@ from qutebrowser.mainwindow.statusbar.percentage import Percentage
|
||||
(25, '[25%]'),
|
||||
(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.
|
||||
|
||||
Args:
|
||||
qtbot: pytestqt.plugin.QtBot fixture
|
||||
y: y position of the page as an int in the range [0, 100].
|
||||
parametrized.
|
||||
expected: expected text given y position. parametrized.
|
||||
"""
|
||||
percentage = Percentage()
|
||||
qtbot.add_widget(percentage)
|
||||
percentage.set_perc(None, y=y)
|
||||
percentage.set_perc(x=None, y=y)
|
||||
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%]'
|
||||
|
Loading…
Reference in New Issue
Block a user