Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 30, 2022
1 parent 4acbd30 commit 1c8d099
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 6 deletions.
93 changes: 91 additions & 2 deletions test/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from qtpy.QtWidgets import QLabel
from qtpy.QtWidgets import QLabel, QWidget, QPushButton, QApplication, QToolButton, QMessageBox

from qthandy import translucent
from qthandy import translucent, hbox, retain_when_hidden, spacer, transparent, busy, btn_popup, ask_confirmation


def test_translucent(qtbot):
Expand All @@ -11,3 +11,92 @@ def test_translucent(qtbot):
translucent(widget)

assert widget.graphicsEffect()


def test_retain_when_hidden(qtbot):
parent = QWidget()
parent.setFixedWidth(300)
hbox(parent)
stretched_btn = QPushButton('Stretched')
btn = QPushButton()
btn.setFixedWidth(100)
parent.layout().addWidget(stretched_btn)
parent.layout().addWidget(btn)

qtbot.addWidget(parent)
parent.show()

prev_btn_size = stretched_btn.width()
retain_when_hidden(btn)
btn.setHidden(True)
qtbot.wait(5)
assert prev_btn_size == stretched_btn.width()


def test_spacer(qtbot):
parent = QWidget()
parent.setFixedWidth(300)
hbox(parent)

btn = QPushButton('Button')
btn.setMinimumWidth(100)

parent.layout().addWidget(spacer())
parent.layout().addWidget(btn)
qtbot.addWidget(parent)
parent.show()

assert btn.width() == 100


def test_spacer_with_max_stretch(qtbot):
parent = QWidget()
parent.setFixedWidth(300)
hbox(parent, 0, 0)

btn = QPushButton('Button')
btn.setMinimumWidth(100)

parent.layout().addWidget(spacer(max_stretch=150))
parent.layout().addWidget(btn)
qtbot.addWidget(parent)
parent.show()

assert btn.width() == 150


def test_transparent_label(qtbot):
lbl = QLabel('Test')
transparent(lbl)


def test_busy(qtbot):
@busy
def busy_func():
assert QApplication.overrideCursor()

assert not QApplication.overrideCursor()
busy_func()
assert not QApplication.overrideCursor()


def test_btn_popup(qtbot):
btn = QToolButton()
qtbot.addWidget(btn)
btn.show()

lbl = QLabel('Test')
btn_popup(btn, lbl)

assert btn.menu()
assert btn.popupMode() == QToolButton.ToolButtonPopupMode.InstantPopup


def test_confirmation(qtbot, monkeypatch):
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes) # confirm
confirmed = ask_confirmation('Confirmation')
assert confirmed

monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.No) # confirm
confirmed = ask_confirmation('Confirmation')
assert not confirmed
6 changes: 2 additions & 4 deletions test/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform

import pytest
from qtpy.QtWidgets import QPushButton, QToolTip
from qtpy.QtWidgets import QPushButton

from qthandy.filter import InstantTooltipEventFilter

Expand All @@ -14,7 +14,5 @@ def test_instant_tooltip(qtbot):

btn.setToolTip('Test button')
btn.installEventFilter(InstantTooltipEventFilter(btn))
qtbot.wait(50)
qtbot.mouseMove(btn)

assert QToolTip.isVisible()
assert QToolTip.text() == 'Test button'

0 comments on commit 1c8d099

Please sign in to comment.