first working tests
This commit is contained in:
51
src/ad_test/test_file_change.py
Normal file
51
src/ad_test/test_file_change.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import food.meal
|
||||
import pytest
|
||||
from appdaemon.appdaemon import AppDaemon
|
||||
from git import Repo
|
||||
|
||||
from .fixtures import ad, base_config
|
||||
from .utils import get_load_order
|
||||
|
||||
|
||||
def reset_file(changed: Path):
|
||||
for p in Path(__file__).parents:
|
||||
if p.with_name(".git").exists():
|
||||
root = p.parent
|
||||
break
|
||||
|
||||
repo = Repo(root)
|
||||
if not changed.is_absolute():
|
||||
changed = root / changed
|
||||
repo.git.checkout("HEAD", "--", changed)
|
||||
|
||||
|
||||
def modify_file(path: Path):
|
||||
file_content = path.read_text()
|
||||
modified_content = re.sub(r"Ham", r"Spam", file_content, flags=re.MULTILINE)
|
||||
modified_content = re.sub(r"ham", r"spam", modified_content, flags=re.MULTILINE)
|
||||
path.write_text(modified_content)
|
||||
|
||||
|
||||
def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture):
|
||||
assert isinstance(ad, AppDaemon)
|
||||
|
||||
# ad.loop.run_until_complete(asyncio.sleep(2.0))
|
||||
|
||||
module_file = Path(food.meal.__file__)
|
||||
reset_file(module_file)
|
||||
modify_file(module_file)
|
||||
|
||||
logging.getLogger("AppDaemon").propagate = True
|
||||
with caplog.at_level(logging.DEBUG, logger="AppDaemon._app_management"):
|
||||
# running_ad.loop.run_until_complete(delayed_stop(running_ad, 2.0))
|
||||
print("waiting in test")
|
||||
ad.loop.run_until_complete(asyncio.sleep(2.0))
|
||||
|
||||
module_load_order = get_load_order(caplog)
|
||||
assert module_load_order == ["food.meal", "restaurant"]
|
||||
print("done")
|
||||
Reference in New Issue
Block a user