Compare commits
5 Commits
c10d280dcb
...
81da8be655
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81da8be655 | ||
|
|
a0add54445 | ||
|
|
6c50657e5b | ||
|
|
7bb5d1debe | ||
|
|
4547668c2b |
@@ -5,3 +5,5 @@ hello_world:
|
||||
simple_app:
|
||||
module: simple
|
||||
class: SimpleApp
|
||||
dependencies:
|
||||
- hello_world
|
||||
15
conf/apps/family/chain.yaml
Normal file
15
conf/apps/family/chain.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
child:
|
||||
module: child
|
||||
class: Child
|
||||
|
||||
parent:
|
||||
module: parent
|
||||
class: Parent
|
||||
dependencies:
|
||||
- child
|
||||
|
||||
grand-parent:
|
||||
module: grand_parent
|
||||
class: GrandParent
|
||||
dependencies:
|
||||
- parent
|
||||
5
conf/apps/family/child.py
Normal file
5
conf/apps/family/child.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
class Child(ADAPI):
|
||||
def initialize(self):
|
||||
self.log(f"{self.__class__.__name__} Initialized")
|
||||
5
conf/apps/family/grand_parent.py
Normal file
5
conf/apps/family/grand_parent.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
class GrandParent(ADAPI):
|
||||
def initialize(self):
|
||||
self.log(f"{self.__class__.__name__} Initialized")
|
||||
5
conf/apps/family/parent.py
Normal file
5
conf/apps/family/parent.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
class Parent(ADAPI):
|
||||
def initialize(self):
|
||||
self.log(f"{self.__class__.__name__} Initialized")
|
||||
@@ -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))
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import List
|
||||
import pytest
|
||||
from appdaemon.appdaemon import AppDaemon
|
||||
|
||||
from .utils import get_load_order
|
||||
from .utils import get_load_order, count_error_lines
|
||||
|
||||
|
||||
def validate_app_dependencies(ad: AppDaemon):
|
||||
@@ -41,8 +41,7 @@ def test_startup(ad: AppDaemon, caplog: pytest.LogCaptureFixture):
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
ad.loop.run_until_complete(asyncio.sleep(2.0))
|
||||
|
||||
error_log_lines = [msg for name, lvl, msg in caplog.record_tuples if name.startswith('Error')]
|
||||
assert len(error_log_lines) == 0
|
||||
assert count_error_lines(caplog) == 0
|
||||
assert "Started 'hello_world'" in caplog.text
|
||||
assert 'App initialization complete' in caplog.text
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
@@ -15,3 +16,26 @@ def get_load_order(caplog: pytest.LogCaptureFixture) -> List[str]:
|
||||
if record.name == 'AppDaemon._app_management':
|
||||
if 'Determined module load order' in record.msg:
|
||||
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