Fix tabwidget tests

This commit is contained in:
Jay Kamat 2018-09-27 19:17:46 -07:00
parent 14e55eae49
commit de148bb778
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 12 additions and 15 deletions

View File

@ -613,15 +613,12 @@ class TabBar(QTabBar):
width = self.minimumTabSizeHint(index, ellipsis=False).width()
else:
# Request as much space as possible so we fill the tabbar, let
# Qt shrink us down
width = self.width()
# Qt shrink us down. If for some reason (tests, bugs)
# self.width() gives 0, use a sane min of 10 px
width = max(self.width(), 10)
max_width = config.cache['tabs.max_width']
if max_width > 0:
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)
qtutils.ensure_valid(size)
return size

View File

@ -39,7 +39,6 @@ class TestTabWidget:
monkeypatch.setattr(tabwidget.objects, 'backend',
usertypes.Backend.QtWebKit)
w.show()
# monkeypatch.setattr(w.tabBar(), 'width', w.width)
return w
@pytest.fixture
@ -130,17 +129,18 @@ class TestTabWidget:
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')
normal_size = widget.tabBar().tabRect(0).width() + 100
config_stub.val.tabs.min_width = normal_size
assert widget.tabBar().tabRect(0).width() == normal_size
widget.addTab(fake_web_tab(), 'foobar1')
min_size = widget.tabBar().tabRect(0).width() + 10
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')
normal_size = widget.tabBar().tabRect(0).width() - 10
config_stub.val.tabs.max_width = normal_size
assert widget.tabBar().tabRect(0).width() == normal_size
max_size = widget.tabBar().tabRect(0).width() - 10
config_stub.val.tabs.max_width = max_size
assert widget.tabBar().tabRect(0).width() == max_size
@pytest.mark.parametrize("num_tabs", [4, 10])
def test_add_remove_tab_benchmark(self, benchmark, browser,