diff --git a/kanboard.py b/kanboard.py index f85dae5..1a0c45d 100644 --- a/kanboard.py +++ b/kanboard.py @@ -96,7 +96,9 @@ def __init__( self._timeout = timeout self._ignore_hostname_verification = ignore_hostname_verification - if not loop: + if loop: + self._event_loop = loop + else: try: self._event_loop = asyncio.get_event_loop() except RuntimeError: diff --git a/tests/test_kanboard.py b/tests/test_kanboard.py index 03f42a0..9f77eed 100644 --- a/tests/test_kanboard.py +++ b/tests/test_kanboard.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +import asyncio import types import unittest import warnings @@ -112,6 +113,14 @@ def test_async_call_returns_result(self): result = loop.run_until_complete(self.client.my_method_async()) self.assertEqual(42, result) + def test_custom_event_loop(self): + custom_loop = asyncio.new_event_loop() + try: + client = kanboard.Client(self.url, "username", "password", loop=custom_loop) + self.assertIs(client._event_loop, custom_loop) + finally: + custom_loop.close() + def test_custom_user_agent(self): client = kanboard.Client(self.url, "username", "password", user_agent="CustomAgent/1.0") body = b'{"jsonrpc": "2.0", "result": true, "id": 123}'