Fix tabwidget tests
This commit is contained in:
parent
14e55eae49
commit
de148bb778
@ -613,15 +613,12 @@ class TabBar(QTabBar):
|
|||||||
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
width = self.minimumTabSizeHint(index, ellipsis=False).width()
|
||||||
else:
|
else:
|
||||||
# Request as much space as possible so we fill the tabbar, let
|
# Request as much space as possible so we fill the tabbar, let
|
||||||
# Qt shrink us down
|
# Qt shrink us down. If for some reason (tests, bugs)
|
||||||
width = self.width()
|
# self.width() gives 0, use a sane min of 10 px
|
||||||
|
width = max(self.width(), 10)
|
||||||
max_width = config.cache['tabs.max_width']
|
max_width = config.cache['tabs.max_width']
|
||||||
if max_width > 0:
|
if max_width > 0:
|
||||||
width = min(max_width, width)
|
width = min(max_width, width)
|
||||||
|
|
||||||
# If for some reason (tests, bugs) self.width() gives 0, use a
|
|
||||||
# sane min of 10 px
|
|
||||||
width = max(width, 10)
|
|
||||||
size = QSize(width, height)
|
size = QSize(width, height)
|
||||||
qtutils.ensure_valid(size)
|
qtutils.ensure_valid(size)
|
||||||
return size
|
return size
|
||||||
|
@ -39,7 +39,6 @@ class TestTabWidget:
|
|||||||
monkeypatch.setattr(tabwidget.objects, 'backend',
|
monkeypatch.setattr(tabwidget.objects, 'backend',
|
||||||
usertypes.Backend.QtWebKit)
|
usertypes.Backend.QtWebKit)
|
||||||
w.show()
|
w.show()
|
||||||
# monkeypatch.setattr(w.tabBar(), 'width', w.width)
|
|
||||||
return w
|
return w
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -130,17 +129,18 @@ class TestTabWidget:
|
|||||||
|
|
||||||
benchmark(widget.update_tab_titles)
|
benchmark(widget.update_tab_titles)
|
||||||
|
|
||||||
def test_tab_min_width(self, widget, fake_web_tab, config_stub):
|
def test_tab_min_width(self, widget, fake_web_tab, config_stub, qtbot):
|
||||||
widget.addTab(fake_web_tab(), 'foobar')
|
widget.addTab(fake_web_tab(), 'foobar')
|
||||||
normal_size = widget.tabBar().tabRect(0).width() + 100
|
widget.addTab(fake_web_tab(), 'foobar1')
|
||||||
config_stub.val.tabs.min_width = normal_size
|
min_size = widget.tabBar().tabRect(0).width() + 10
|
||||||
assert widget.tabBar().tabRect(0).width() == normal_size
|
config_stub.val.tabs.min_width = min_size
|
||||||
|
assert widget.tabBar().tabRect(0).width() == min_size
|
||||||
|
|
||||||
def test_tab_max_width(self, widget, fake_web_tab, config_stub):
|
def test_tab_max_width(self, widget, fake_web_tab, config_stub, qtbot):
|
||||||
widget.addTab(fake_web_tab(), 'foobar')
|
widget.addTab(fake_web_tab(), 'foobar')
|
||||||
normal_size = widget.tabBar().tabRect(0).width() - 10
|
max_size = widget.tabBar().tabRect(0).width() - 10
|
||||||
config_stub.val.tabs.max_width = normal_size
|
config_stub.val.tabs.max_width = max_size
|
||||||
assert widget.tabBar().tabRect(0).width() == normal_size
|
assert widget.tabBar().tabRect(0).width() == max_size
|
||||||
|
|
||||||
@pytest.mark.parametrize("num_tabs", [4, 10])
|
@pytest.mark.parametrize("num_tabs", [4, 10])
|
||||||
def test_add_remove_tab_benchmark(self, benchmark, browser,
|
def test_add_remove_tab_benchmark(self, benchmark, browser,
|
||||||
|
Loading…
Reference in New Issue
Block a user