mirror of
https://github.com/pyapp-kit/superqt.git
synced 2026-01-07 21:02:13 +01:00
add test for warning
This commit is contained in:
@@ -29,6 +29,7 @@ SOFTWARE.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from concurrent.futures import Future
|
||||
from contextlib import suppress
|
||||
from enum import IntFlag, auto
|
||||
@@ -223,6 +224,9 @@ def _weak_func(func: Callable[P, R]) -> Callable[P, R]:
|
||||
def weak_func(*args, **kwargs):
|
||||
if method := weak_method():
|
||||
return method(*args, **kwargs)
|
||||
warnings.warn(
|
||||
"Method has been garbage collected", RuntimeWarning, stacklevel=2
|
||||
)
|
||||
|
||||
return weak_func
|
||||
|
||||
|
||||
@@ -226,6 +226,12 @@ def test_qthrottled_does_not_prevent_gc(qtbot):
|
||||
qtbot.waitUntil(thing.tmethod._future.done, timeout=2000)
|
||||
assert mock.call_count == 2
|
||||
|
||||
wm = thing.tmethod
|
||||
assert isinstance(wm, ThrottledCallable)
|
||||
del thing
|
||||
gc.collect()
|
||||
assert thing_ref() is None
|
||||
|
||||
with pytest.warns(RuntimeWarning, match="Method has been garbage collected"):
|
||||
wm()
|
||||
wm._set_future_result()
|
||||
|
||||
Reference in New Issue
Block a user