From 81da8be655b7e7b43783607a18a5044fb6614784 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:36:05 -0500 Subject: [PATCH] added another test for the child being modified --- src/ad_test/test_file_change.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ad_test/test_file_change.py b/src/ad_test/test_file_change.py index 3288330..070507f 100644 --- a/src/ad_test/test_file_change.py +++ b/src/ad_test/test_file_change.py @@ -3,12 +3,15 @@ import logging import re from pathlib import Path +# import child import food.menu import pytest from appdaemon.appdaemon import AppDaemon 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): @@ -67,3 +70,25 @@ def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config assert "Started 'my_restaurant'" in caplog.text finally: 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))