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:
Grzegorz Bokota
2023-08-18 20:20:11 +02:00
committed by GitHub
parent 8457563f49
commit 462eeada93
2 changed files with 44 additions and 1 deletions

View File

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