mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-16 11:10:06 +01:00
fix: Add descriptive exception when fail to add instance to weakref dictionary (#189)
* add weakref information and test * more information * Update src/superqt/utils/_throttler.py --------- Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
This commit is contained in:
@@ -87,6 +87,41 @@ def test_debouncer_method_definition(qtbot):
|
||||
mock2.assert_called_once()
|
||||
|
||||
|
||||
def test_class_with_slots(qtbot):
|
||||
class A:
|
||||
__slots__ = ("count", "__weakref__")
|
||||
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
|
||||
@qdebounced(timeout=4)
|
||||
def callback(self):
|
||||
self.count += 1
|
||||
|
||||
a = A()
|
||||
for _ in range(10):
|
||||
a.callback()
|
||||
|
||||
qtbot.wait(5)
|
||||
assert a.count == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("qapp")
|
||||
def test_class_with_slots_except():
|
||||
class A:
|
||||
__slots__ = ("count",)
|
||||
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
|
||||
@qdebounced(timeout=4)
|
||||
def callback(self):
|
||||
self.count += 1
|
||||
|
||||
with pytest.raises(TypeError, match="To use qthrottled or qdebounced"):
|
||||
A().callback()
|
||||
|
||||
|
||||
def test_throttled(qtbot):
|
||||
mock1 = Mock()
|
||||
mock2 = Mock()
|
||||
|
||||
Reference in New Issue
Block a user