mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-15 18:50:05 +01:00
fix: fix callback of throttled/debounced decorated functions with mismatched args (#184)
* fix: fix throttled inspection * build: change typing-ext deps * fix: use inspect.signature * use get_max_args * fix: fix typing
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from qtpy.QtCore import QObject, Signal
|
||||
|
||||
from superqt.utils import qdebounced, qthrottled
|
||||
|
||||
|
||||
@@ -41,3 +44,29 @@ def test_throttled(qtbot):
|
||||
qtbot.wait(5)
|
||||
assert mock1.call_count == 2
|
||||
assert mock2.call_count == 10
|
||||
|
||||
|
||||
@pytest.mark.parametrize("deco", [qthrottled, qdebounced])
|
||||
def test_ensure_throttled_sig_inspection(deco, qtbot):
|
||||
mock = Mock()
|
||||
|
||||
class Emitter(QObject):
|
||||
sig = Signal(int, int, int)
|
||||
|
||||
@deco
|
||||
def func(a: int, b: int):
|
||||
"""docstring"""
|
||||
mock(a, b)
|
||||
|
||||
obj = Emitter()
|
||||
obj.sig.connect(func)
|
||||
|
||||
# this is the crux of the test...
|
||||
# we emit 3 args, but the function only takes 2
|
||||
# this should normally work fine in Qt.
|
||||
# testing here that the decorator doesn't break it.
|
||||
with qtbot.waitSignal(func.triggered, timeout=1000):
|
||||
obj.sig.emit(1, 2, 3)
|
||||
mock.assert_called_once_with(1, 2)
|
||||
assert func.__doc__ == "docstring"
|
||||
assert func.__name__ == "func"
|
||||
|
||||
Reference in New Issue
Block a user