craftbeerpi4-pione/tests/test_logger.py

36 lines
976 B
Python
Raw Normal View History

2019-08-05 20:51:20 +02:00
import asyncio
import glob
from aiohttp.test_utils import unittest_run_loop
from tests.cbpi_config_fixture import CraftBeerPiTestCase
import os
2019-08-05 20:51:20 +02:00
class LoggerTestCase(CraftBeerPiTestCase):
2019-08-05 20:51:20 +02:00
async def test_log_data(self):
os.makedirs(os.path.join(".", "tests", "logs"), exist_ok=True)
2023-05-14 17:43:48 +02:00
log_name = "unconfigured_test_sensor_ID"
2019-08-05 20:51:20 +02:00
#clear all logs
2019-08-05 23:00:18 +02:00
self.cbpi.log.clear_log(log_name)
2023-05-14 17:43:48 +02:00
assert len(glob.glob(os.path.join(self.cbpi.log.logsFolderPath, f"sensor_{log_name}.log*"))) == 0
2019-08-05 20:51:20 +02:00
# 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')
2019-08-05 23:00:18 +02:00
assert len(data["time"]) == 5
2019-08-05 20:51:20 +02:00
2019-08-05 23:00:18 +02:00
assert self.cbpi.log.zip_log_data(log_name) is not None
2019-08-05 20:51:20 +02:00
2019-08-05 23:00:18 +02:00
self.cbpi.log.clear_zip(log_name)
2019-08-05 20:51:20 +02:00
2019-08-05 23:00:18 +02:00
self.cbpi.log.clear_log(log_name)
2019-08-05 20:51:20 +02:00