X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fcommon.git;a=blobdiff_plain;f=osm_common%2Ftests%2Ftest_msglocal.py;fp=osm_common%2Ftests%2Ftest_msglocal.py;h=b40b75c1e5a120217a101bebcbc10e7a611a2195;hp=fb745867ae424897faac30e0b72e2fc0c4e215f0;hb=a06b854f2b278aaee015fc1f76015895f8cf50c1;hpb=b2d732a70efa33e4bc478d351d64bc4adb4ea332 diff --git a/osm_common/tests/test_msglocal.py b/osm_common/tests/test_msglocal.py index fb74586..b40b75c 100644 --- a/osm_common/tests/test_msglocal.py +++ b/osm_common/tests/test_msglocal.py @@ -16,7 +16,7 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: esousa@whitestack.com or alfonso.tiernosepulveda@telefonica.com ## - +import asyncio import http import logging import os @@ -437,7 +437,7 @@ def test_read_exception(msg_local_with_data, blocks): (["topic", "topic1", "topic2"], [{"key": "value"}, {"key1": "value1"}]), ], ) -def test_aioread(msg_local_with_data, event_loop, topics, datas): +def test_aioread(msg_local_with_data, topics, datas): def write_to_topic(topics, datas): time.sleep(2) for topic in topics: @@ -455,9 +455,7 @@ def test_aioread(msg_local_with_data, event_loop, topics, datas): t.start() for topic in topics: for data in datas: - recv = event_loop.run_until_complete( - msg_local_with_data.aioread(topic, event_loop) - ) + recv = asyncio.run(msg_local_with_data.aioread(topic)) recv_topic, recv_key, recv_msg = recv key = list(data.keys())[0] val = data[key] @@ -467,22 +465,22 @@ def test_aioread(msg_local_with_data, event_loop, topics, datas): t.join() -def test_aioread_exception(msg_local_with_data, event_loop): +def test_aioread_exception(msg_local_with_data): msg_local_with_data.files_read = MagicMock() msg_local_with_data.files_read.__contains__.side_effect = Exception() with pytest.raises(MsgException) as excinfo: - event_loop.run_until_complete(msg_local_with_data.aioread("topic1", event_loop)) + asyncio.run(msg_local_with_data.aioread("topic1")) assert str(excinfo.value).startswith(empty_exception_message()) assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR -def test_aioread_general_exception(msg_local_with_data, event_loop): +def test_aioread_general_exception(msg_local_with_data): msg_local_with_data.read = MagicMock() msg_local_with_data.read.side_effect = Exception() with pytest.raises(MsgException) as excinfo: - event_loop.run_until_complete(msg_local_with_data.aioread("topic1", event_loop)) + asyncio.run(msg_local_with_data.aioread("topic1")) assert str(excinfo.value).startswith(empty_exception_message()) assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR @@ -503,9 +501,9 @@ def test_aioread_general_exception(msg_local_with_data, event_loop): ("test_topic", "test_none", None), ], ) -def test_aiowrite(msg_local_config, event_loop, topic, key, msg): +def test_aiowrite(msg_local_config, topic, key, msg): file_path = msg_local_config.path + topic - event_loop.run_until_complete(msg_local_config.aiowrite(topic, key, msg)) + asyncio.run(msg_local_config.aiowrite(topic, key, msg)) assert os.path.exists(file_path) with open(file_path, "r") as stream: @@ -530,12 +528,10 @@ def test_aiowrite(msg_local_config, event_loop, topic, key, msg): ("test_topic", "test_none", None, 3), ], ) -def test_aiowrite_with_multiple_calls( - msg_local_config, event_loop, topic, key, msg, times -): +def test_aiowrite_with_multiple_calls(msg_local_config, topic, key, msg, times): file_path = msg_local_config.path + topic for _ in range(times): - event_loop.run_until_complete(msg_local_config.aiowrite(topic, key, msg)) + asyncio.run(msg_local_config.aiowrite(topic, key, msg)) assert os.path.exists(file_path) with open(file_path, "r") as stream: @@ -546,11 +542,11 @@ def test_aiowrite_with_multiple_calls( } -def test_aiowrite_exception(msg_local_config, event_loop): +def test_aiowrite_exception(msg_local_config): msg_local_config.files_write = MagicMock() msg_local_config.files_write.__contains__.side_effect = Exception() with pytest.raises(MsgException) as excinfo: - event_loop.run_until_complete(msg_local_config.aiowrite("test", "test", "test")) + asyncio.run(msg_local_config.aiowrite("test", "test", "test")) assert str(excinfo.value).startswith(empty_exception_message()) assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR