Skip to content

Commit

Permalink
Merge pull request #316
Browse files Browse the repository at this point in the history
Standalone test
  • Loading branch information
thusser authored Dec 19, 2023
2 parents b1b28e9 + 549b482 commit 578837d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyobs/modules/test/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ async def _message_func(self):
"""Thread function for async processing."""
# loop until closing
while True:
# log message
log.info(self._message)
await self._loop()

# sleep a little
await asyncio.sleep(self._interval)
async def _loop(self):
log.info(self._message)
await asyncio.sleep(self._interval)


__all__ = ["StandAlone"]
Empty file added tests/modules/test/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions tests/modules/test/standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio
import logging

import pytest

from pyobs.modules.test import StandAlone


def test_default():
module = StandAlone()
assert module._message == "Hello world"
assert module._interval == 10


@pytest.mark.asyncio
async def test_loop(mocker, caplog):
mocker.patch("asyncio.sleep", return_value=None)
module = StandAlone("Testmessage", 3)

with caplog.at_level(logging.INFO):
await module._loop()

assert caplog.messages[0] == "Testmessage"
asyncio.sleep.assert_called_once_with(3)


@pytest.mark.asyncio
async def test_background_task():
module = StandAlone()
assert module._message_func in module._background_tasks

0 comments on commit 578837d

Please sign in to comment.