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() 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

View File

@ -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,