Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/unit/test_log/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import io
import logging

import pytest

import enapter.log


@pytest.fixture(autouse=True)
def reset_logger():
original_level = enapter.log.LOGGER.level
original_handlers = enapter.log.LOGGER.handlers.copy()
yield
enapter.log.LOGGER.setLevel(original_level)
enapter.log.LOGGER.handlers = original_handlers


def test_configure_level_none():
enapter.log.configure(level=None)
assert len(enapter.log.LOGGER.handlers) == 1
assert isinstance(enapter.log.LOGGER.handlers[0], logging.NullHandler)


def test_configure_level_str():
enapter.log.configure(level="DEBUG")
assert enapter.log.LOGGER.level == logging.DEBUG
assert len(enapter.log.LOGGER.handlers) == 1
handler = enapter.log.LOGGER.handlers[0]
assert isinstance(handler, logging.StreamHandler)
assert isinstance(handler.formatter, enapter.log.JSONFormatter)


def test_configure_level_int():
enapter.log.configure(level=logging.INFO)
assert enapter.log.LOGGER.level == logging.INFO
assert len(enapter.log.LOGGER.handlers) == 1
handler = enapter.log.LOGGER.handlers[0]
assert isinstance(handler, logging.StreamHandler)
assert isinstance(handler.formatter, enapter.log.JSONFormatter)


def test_configure_custom_stream():
stream = io.StringIO()
enapter.log.configure(level=logging.INFO, stream=stream)
assert len(enapter.log.LOGGER.handlers) == 1
handler = enapter.log.LOGGER.handlers[0]
assert isinstance(handler, logging.StreamHandler)
assert handler.stream is stream
12 changes: 6 additions & 6 deletions tests/unit/test_standalone/test_mqtt_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def test_publish_properties():
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_properties.assert_called()
last_call = device_channel.publish_properties.call_args
published_properties = last_call.kwargs["properties"]
Expand All @@ -80,7 +80,7 @@ async def test_publish_telemetry():
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_telemetry.assert_called()
last_call = device_channel.publish_telemetry.call_args
published_telemetry = last_call.kwargs["telemetry"]
Expand All @@ -103,7 +103,7 @@ async def test_publish_logs(log_severity, persist_logs) -> None:
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_log.assert_called()
last_call = device_channel.publish_log.call_args
published_log = last_call.kwargs["log"]
Expand All @@ -129,7 +129,7 @@ async def test_publish_properties_exception():
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_properties.assert_called()


Expand All @@ -147,7 +147,7 @@ async def test_publish_telemetry_exception():
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_telemetry.assert_called()


Expand All @@ -165,7 +165,7 @@ async def test_publish_logs_exception():
device=device,
task_group=tg,
):
await asyncio.sleep(0.02)
await asyncio.sleep(0.1)
device_channel.publish_log.assert_called()


Expand Down
Loading