Skip to content

Commit

Permalink
test cov
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Nov 4, 2024
1 parent 1948399 commit a78324e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/psygnal/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,9 @@ def emit_fast(self, *args: Any) -> None:
f"RecursionError when "
f"emitting signal {self.name!r} with args {args}"
) from e
except EmitLoopError as e: # pragma: no cover
raise e
except Exception as cb_err:
if isinstance(cb_err, EmitLoopError):
raise cb_err
loop_err = EmitLoopError(exc=cb_err, signal=self).with_traceback(
cb_err.__traceback__
)
Expand Down Expand Up @@ -1245,9 +1245,9 @@ def _run_emit_loop(self, args: tuple[Any, ...]) -> None:
f"RecursionError when "
f"emitting signal {self.name!r} with args {args}"
) from e
except EmitLoopError as e:
raise e
except Exception as cb_err:
if isinstance(cb_err, EmitLoopError):
raise cb_err
loop_err = EmitLoopError(
exc=cb_err,
signal=self,
Expand Down
51 changes: 51 additions & 0 deletions tests/test_psygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,57 @@ def test_emit_fast():
# calling directly also works
emitter.one_int(1)
mock.assert_called_once_with(1)
mock.reset_mock()

with emitter.one_int.blocked():
emitter.one_int.emit_fast(2)
mock.assert_not_called()

with emitter.one_int.paused():
emitter.one_int.emit_fast(3)
mock.assert_not_called()
emitter.one_int.emit_fast(4)
mock.assert_has_calls([call(3), call(4)])


def test_emit_fast_errors():
emitter = Emitter()
err = ValueError()

@emitter.one_int.connect
def boom(v: int) -> None:
raise err

import re

error_re = re.compile(
"signal 'tests.test_psygnal.Emitter.one_int'" f".*{re.escape(__file__)}",
re.DOTALL,
)
with pytest.raises(EmitLoopError, match=error_re):
emitter.one_int.emit_fast(42)


def test_emit_fast_recursion_errors():
"""Test emit_fast method."""
emitter = Emitter()
emitter.one_int.emit_fast(1)

@emitter.one_int.connect
def callback() -> None:
emitter.one_int.emit(2)

with pytest.raises(RecursionError):
emitter.one_int.emit_fast(3)

emitter.one_int.disconnect(callback)

@emitter.one_int.connect
def callback() -> None:
emitter.one_int.emit_fast(2)

with pytest.raises(RecursionError):
emitter.one_int.emit_fast(3)


def test_decorator():
Expand Down

0 comments on commit a78324e

Please sign in to comment.