added another test for the child being modified

This commit is contained in:
John Lancaster
2024-08-14 00:36:05 -05:00
parent a0add54445
commit 81da8be655

View File

@@ -3,12 +3,15 @@ import logging
import re import re
from pathlib import Path from pathlib import Path
# import child
import food.menu import food.menu
import pytest import pytest
from appdaemon.appdaemon import AppDaemon from appdaemon.appdaemon import AppDaemon
from git import Repo from git import Repo
from .utils import get_load_order from .utils import count_error_lines, get_app_orders, get_load_order, get_loaded_apps
INDENT = ' ' * 4
def reset_file(repo: Repo, changed: Path): def reset_file(repo: Repo, changed: Path):
@@ -67,3 +70,25 @@ def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config
assert "Started 'my_restaurant'" in caplog.text assert "Started 'my_restaurant'" in caplog.text
finally: finally:
reset_file(config_repo, module_file) reset_file(config_repo, module_file)
def test_modification_child(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
assert isinstance(ad, AppDaemon)
module_file = Path(__file__).parents[2] / 'conf/apps/family/child.py'
file_content = module_file.read_text()
file_content += (INDENT * 2) + "self.log(f'Modified {self.__class__.__name__}')\n"
module_file.write_text(file_content)
try:
with caplog.at_level(logging.DEBUG):
ad.loop.run_until_complete(asyncio.sleep(1.0))
assert count_error_lines(caplog) == 0
assert get_loaded_apps(caplog) == {'child'}
assert get_app_orders(caplog, 'stop') == ['child', 'parent', 'grand-parent']
assert get_app_orders(caplog, 'start') == ['child', 'parent', 'grand-parent']
finally:
reset_file(config_repo, module_file)
ad.loop.run_until_complete(asyncio.sleep(1.0))