mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-16 03:00:05 +01:00
Qthrottler and debouncer (#62)
* initial working throttler * complete typing and docs * basic test * fix future subscript * touch ups * Update src/superqt/utils/_throttler.py Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> * Update src/superqt/utils/_throttler.py Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> * Update src/superqt/utils/_throttler.py Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com> Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
This commit is contained in:
43
tests/test_throttler.py
Normal file
43
tests/test_throttler.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from unittest.mock import Mock
|
||||
|
||||
from superqt.utils import qdebounced, qthrottled
|
||||
|
||||
|
||||
def test_debounced(qtbot):
|
||||
mock1 = Mock()
|
||||
mock2 = Mock()
|
||||
|
||||
@qdebounced(timeout=5)
|
||||
def f1() -> str:
|
||||
mock1()
|
||||
|
||||
def f2() -> str:
|
||||
mock2()
|
||||
|
||||
for _ in range(10):
|
||||
f1()
|
||||
f2()
|
||||
|
||||
qtbot.wait(5)
|
||||
mock1.assert_called_once()
|
||||
assert mock2.call_count == 10
|
||||
|
||||
|
||||
def test_throttled(qtbot):
|
||||
mock1 = Mock()
|
||||
mock2 = Mock()
|
||||
|
||||
@qthrottled(timeout=5)
|
||||
def f1() -> str:
|
||||
mock1()
|
||||
|
||||
def f2() -> str:
|
||||
mock2()
|
||||
|
||||
for _ in range(10):
|
||||
f1()
|
||||
f2()
|
||||
|
||||
qtbot.wait(5)
|
||||
assert mock1.call_count == 2
|
||||
assert mock2.call_count == 10
|
||||
Reference in New Issue
Block a user