Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Nov 9, 2023
1 parent b074644 commit 2c295d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/psygnal/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
if isinstance(cb, WeakCallback):
cb_name = cb.slot_repr()
else:
cb_name = cb.__qualname__
cb_name = getattr(cb, "__qualname__", repr(cb))
super().__init__(
MSG.format(
sig=sig_name,
Expand Down
27 changes: 26 additions & 1 deletion tests/test_weak_callable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gc
from functools import partial
from typing import Any
from unittest.mock import Mock
from weakref import ref

Expand Down Expand Up @@ -178,7 +179,7 @@ def func(x):
assert dp.keywords == p.keywords


def test_queued_callbacks():
def test_queued_callbacks() -> None:
from psygnal._queue import QueuedCallback

def func(x):
Expand All @@ -189,3 +190,27 @@ def func(x):

assert qcb.dereference() is func
assert qcb(1) == 1


def test_cb_raises() -> None:
from psygnal import EmitLoopError

m = str(EmitLoopError(weak_callback(print), (1,), RuntimeError("test")))
assert "an error occurred in callback 'module.print'" in m
m = str(EmitLoopError(print, (1,), RuntimeError("test")))
assert " an error occurred in callback 'print'" in m

class T:
x = 1

def __setitem__(self, *_: Any) -> Any:
pass

t = T()
cb = weak_callback(setattr, t, "x")
m = str(EmitLoopError(cb, (2,), RuntimeError("test")))
assert "an error occurred in callback \"setattr" in m

cb = weak_callback(t.__setitem__, "x")
m = str(EmitLoopError(cb, (2,), RuntimeError("test")))
assert '.T.__setitem__' in m

0 comments on commit 2c295d5

Please sign in to comment.