2019-08-05 20:51:20 +02:00
|
|
|
import asyncio
|
|
|
|
import glob
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
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
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
class LoggerTestCase(CraftBeerPiTestCase):
|
2019-08-05 20:51:20 +02:00
|
|
|
|
|
|
|
async def test_log_data(self):
|
|
|
|
|
2022-09-24 15:19:34 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|