Files
aiomql/tests/live/unit/test_bot_and_executor.py
T

63 lines
1.9 KiB
Python
Raw Normal View History

2024-10-28 06:36:10 +01:00
import asyncio
import pytest
from aiomql.lib.bot import Bot
class TestBotFactoryAndExecutor:
@classmethod
def setup_class(cls):
cls.bot = Bot()
2024-11-08 05:41:23 +01:00
cls.sync_bot = Bot()
2024-10-28 06:36:10 +01:00
2024-11-04 00:32:51 +01:00
@pytest.fixture(scope="class", autouse=True)
2024-10-28 06:36:10 +01:00
async def initialize(self):
self.bot.add_coroutine(coroutine=self.coro_one)
self.bot.add_coroutine(coroutine=self.coro_two)
self.bot.add_function(function=self.fun_one)
self.bot.add_coroutine(coroutine=self.coro_thread, on_separate_thread=True)
await self.bot.initialize()
2024-11-08 05:41:23 +01:00
@pytest.fixture(scope="class", autouse=True)
def initialize_sync(self):
self.sync_bot.add_coroutine(coroutine=self.coro_one)
self.sync_bot.add_coroutine(coroutine=self.coro_two)
self.sync_bot.add_function(function=self.fun_one)
self.sync_bot.add_coroutine(coroutine=self.coro_thread, on_separate_thread=True)
self.sync_bot.initialize_sync()
2024-10-28 06:36:10 +01:00
@staticmethod
def fun_one():
2024-11-04 00:32:51 +01:00
print("function one")
2024-10-28 06:36:10 +01:00
@staticmethod
async def coro_thread():
while True:
2024-11-04 00:32:51 +01:00
print("coroutine thread")
2024-10-28 06:36:10 +01:00
await asyncio.sleep(1)
@staticmethod
async def coro_one():
while True:
2024-11-04 00:32:51 +01:00
print("coroutine one")
2024-10-28 06:36:10 +01:00
await asyncio.sleep(1)
@staticmethod
async def coro_two():
while True:
2024-11-04 00:32:51 +01:00
print("coroutine two")
2024-10-28 06:36:10 +01:00
await asyncio.sleep(1)
def test_add_workers(self):
2024-10-29 14:03:32 +01:00
assert len(self.bot.executor.coroutines) == 3
assert len(self.bot.executor.functions) == 1
2024-10-28 06:36:10 +01:00
# task_queue already added coroutine_thread
assert len(self.bot.executor.coroutine_threads) == 2
2024-11-08 05:41:23 +01:00
def test_sync_add_workers(self):
assert len(self.sync_bot.executor.coroutines) == 3
assert len(self.sync_bot.executor.functions) == 1
# task_queue already added coroutine_thread
assert len(self.sync_bot.executor.coroutine_threads) == 2