Skip to content

Commit

Permalink
Also raise for get_dispatcher_event and emission_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarryr authored May 30, 2023
1 parent 030a519 commit c463814
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pydispatch/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,21 @@ def get_dispatcher_event(self, name):
Returns:
The :class:`Event` instance for the event or property definition
Raises:
DoesNotExistError: If no event or property with the given name exists
.. versionchanged:: 0.2.2
:class:`DoesNotExistError` is now raised if the event or property
does not exist
.. versionadded:: 0.1.0
"""
e = self.__property_events.get(name)
if e is None:
e = self.__events[name]
try:
e = self.__events[name]
except KeyError:
raise DoesNotExistError(name)
return e
def emission_lock(self, name):
"""Holds emission of events and dispatches the last event on release
Expand Down Expand Up @@ -356,9 +366,14 @@ def emission_lock(self, name):
The context manager is re-entrant, meaning that multiple calls to
this method within nested context scopes are possible.
Raises:
DoesNotExistError: If no event or property with the given name exists
.. versionchanged:: 0.2.2
:class:`DoesNotExistError` is now raised if the event or property
does not exist
.. _PEP 492: https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with
"""
e = self.__property_events.get(name)
if e is None:
e = self.__events[name]
e = self.get_dispatcher_event(name)
return e.emission_lock
8 changes: 8 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def callback(*args, **kwargs):
sender.emit('foo')
assert '"foo"' in str(excinfo.value)

with pytest.raises(DoesNotExistError) as excinfo:
e = sender.get_dispatcher_event('foo')
assert '"foo"' in str(excinfo.value)

with pytest.raises(DoesNotExistError) as excinfo:
lock = sender.emission_lock('foo')
assert '"foo"' in str(excinfo.value)

def test_register_existing_event():
from pydispatch import Dispatcher, EventExistsError

Expand Down

0 comments on commit c463814

Please sign in to comment.