Skip to content

Commit

Permalink
Add testing for async
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Feb 14, 2024
1 parent 4bf2a99 commit 7115f71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
flake8
pytest
pytest-asyncio
tox
mypy>=1.7.0
bump-my-version>=0.12.0
21 changes: 17 additions & 4 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def temp_method2():
return None


async def async_temp_method3():
return None


def except_method():
raise Exception

Expand All @@ -26,10 +30,18 @@ def test_add_methods():
assert handler._methods == {"temp_method1": temp_method1, "temp_method2": temp_method2}


def test_call():
@pytest.mark.asyncio
async def test_call():
handler = EventHandler()
handler.add_method(temp_method1)
assert handler("temp_method1") is None
assert await handler("temp_method1") is None


@pytest.mark.asyncio
async def test_call_async():
handler = EventHandler()
handler.add_method(async_temp_method3)
assert await handler("async_temp_method3") is None


def test_add_exception_handler():
Expand All @@ -38,8 +50,9 @@ def test_add_exception_handler():
assert handler._handlers == {Exception: temp_method1}


def test_call_exception():
@pytest.mark.asyncio
async def test_call_exception():
handler = EventHandler()
handler.add_method(except_method)
with pytest.raises(Exception):
handler("except_method")
await handler("except_method")
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package_name = "pyflowlauncher"
envlist = lint, type, py{38,39,310,311,312}

[testenv]
deps = pytest
deps =
pytest
pytest-asyncio
commands =
pytest {posargs:tests}

Expand Down

0 comments on commit 7115f71

Please sign in to comment.