added try statement
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
@@ -45,6 +46,7 @@ def ad(base_config: AppDaemonConfig):
|
||||
loop = asyncio.new_event_loop()
|
||||
|
||||
ad = AppDaemon(Logging(), loop, base_config)
|
||||
logging.getLogger('AppDaemon').propagate = True
|
||||
yield ad
|
||||
ad.stop()
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def modify_file(path: Path):
|
||||
path.write_text(modified_content)
|
||||
|
||||
|
||||
def insert_importerror(path: Path):
|
||||
def insert_import_error(path: Path):
|
||||
file_content = path.read_text().splitlines()
|
||||
file_content.insert(0, 'raise ImportError')
|
||||
path.write_text('\n'.join(file_content))
|
||||
@@ -36,22 +36,24 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo
|
||||
module_file = Path(food.meal.__file__)
|
||||
modify_file(module_file)
|
||||
|
||||
logging.getLogger('AppDaemon').propagate = True
|
||||
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):
|
||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||
try:
|
||||
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):
|
||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||
|
||||
module_load_order = get_load_order(caplog)
|
||||
assert module_load_order == ['food.meal', 'restaurant']
|
||||
module_load_order = get_load_order(caplog)
|
||||
assert module_load_order == ['food.meal', 'restaurant']
|
||||
|
||||
reset_file(config_repo, module_file)
|
||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||
finally:
|
||||
reset_file(config_repo, module_file)
|
||||
ad.loop.run_until_complete(asyncio.sleep(1.0))
|
||||
|
||||
|
||||
def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
|
||||
assert isinstance(ad, AppDaemon)
|
||||
|
||||
module_file = Path(food.meal.__file__)
|
||||
insert_importerror(module_file)
|
||||
insert_import_error(module_file)
|
||||
|
||||
try:
|
||||
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):
|
||||
|
||||
Reference in New Issue
Block a user