craftbeerpi4-pione/tests/test_logger.py
prash3r e7aa0a64c7 repairs log_file_controller.py.
I seem to have exidentally search and replaced some
needed glob.glob calls when adding dinamic log location,
which should now be repaired.
There also was a mysterious cbpi_dashboard_1.json appearing
in the wrong folder which now inside the dashboard folder.
I also figured out how to run tests locally,
they should now respect the dynamic folder paths.
2022-09-24 15:19:34 +02:00

36 lines
968 B
Python

import asyncio
import glob
from aiohttp.test_utils import unittest_run_loop
from tests.cbpi_config_fixture import CraftBeerPiTestCase
import os
class LoggerTestCase(CraftBeerPiTestCase):
@unittest_run_loop
async def test_log_data(self):
os.makedirs(os.path.join(".", "tests", "logs"), exist_ok=True)
log_name = "test"
#clear all logs
self.cbpi.log.clear_log(log_name)
assert len(glob.glob(os.path.join(".", "tests", "logs", f"sensor_{log_name}.log*"))) == 0
# write log entries
for i in range(5):
print(log_name)
self.cbpi.log.log_data(log_name, 222)
await asyncio.sleep(1)
# read log data
data = await self.cbpi.log.get_data(log_name, sample_rate='1s')
assert len(data["time"]) == 5
assert self.cbpi.log.zip_log_data(log_name) is not None
self.cbpi.log.clear_zip(log_name)
self.cbpi.log.clear_log(log_name)