added some utils functions
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import re
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -15,3 +16,26 @@ def get_load_order(caplog: pytest.LogCaptureFixture) -> List[str]:
|
|||||||
if record.name == 'AppDaemon._app_management':
|
if record.name == 'AppDaemon._app_management':
|
||||||
if 'Determined module load order' in record.msg:
|
if 'Determined module load order' in record.msg:
|
||||||
return record.args[0]
|
return record.args[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger_records(caplog: pytest.LogCaptureFixture, name: str):
|
||||||
|
for record in caplog.records:
|
||||||
|
if record.name == name:
|
||||||
|
yield record
|
||||||
|
|
||||||
|
|
||||||
|
def get_app_orders(caplog: pytest.LogCaptureFixture, phase: str) -> List[str]:
|
||||||
|
for record in get_logger_records(caplog, 'AppDaemon._app_management'):
|
||||||
|
if re.search(f'App {phase} order', record.msg):
|
||||||
|
return record.args[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_loaded_apps(caplog: pytest.LogCaptureFixture):
|
||||||
|
for record in get_logger_records(caplog, 'AppDaemon._app_management'):
|
||||||
|
if re.search('Apps to be loaded', record.msg):
|
||||||
|
return record.args[0]
|
||||||
|
|
||||||
|
|
||||||
|
def count_error_lines(caplog: pytest.LogCaptureFixture) -> int:
|
||||||
|
error_log_lines = [msg for name, lvl, msg in caplog.record_tuples if name.startswith('Error')]
|
||||||
|
return len(error_log_lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user