Skip to content

Commit

Permalink
add except handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Jan 25, 2024
1 parent 3ce7bbb commit 7f87601
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from pyflowlauncher.event import EventHandler


Expand All @@ -9,6 +10,10 @@ def temp_method2():
return None


def except_method():
raise Exception


def test_add_method():
handler = EventHandler()
handler.add_method(temp_method1)
Expand All @@ -25,3 +30,16 @@ def test_call():
handler = EventHandler()
handler.add_method(temp_method1)
assert handler("temp_method1") is None


def test_add_exception_handler():
handler = EventHandler()
handler.add_exception_handler(Exception, temp_method1)
assert handler._handlers == {Exception: temp_method1}


def test_call_exception():
handler = EventHandler()
handler.add_method(except_method)
with pytest.raises(Exception):
handler("except_method")
11 changes: 11 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ def test_action():
plugin = Plugin()
action = plugin.action(query)
assert action == {'method': 'query', 'parameters': []}


def test_exception_handler():
plugin = Plugin()

@plugin.on_except(KeyError)
def action(e: Exception):
print('OH NO!')
return {'result': [{'title': 'title', 'subtitle': 'subtitle', 'icon': 'icon.png'}]}

assert plugin._event_handler._handlers == {KeyError: action}

0 comments on commit 7f87601

Please sign in to comment.