removed single use functions
This commit is contained in:
@@ -3,41 +3,29 @@ 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 count_error_lines, get_app_orders, get_load_order, get_loaded_apps
|
||||
from .utils import (
|
||||
count_error_lines,
|
||||
get_app_orders,
|
||||
get_load_order,
|
||||
get_loaded_apps,
|
||||
reset_file,
|
||||
)
|
||||
|
||||
INDENT = ' ' * 4
|
||||
|
||||
|
||||
def reset_file(repo: Repo, changed: Path):
|
||||
if not changed.is_absolute():
|
||||
changed = Path(repo.working_tree_dir) / changed
|
||||
repo.git.checkout('HEAD', '--', changed)
|
||||
def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
|
||||
module_file = Path(food.menu.__file__)
|
||||
|
||||
|
||||
def modify_file(path: Path):
|
||||
file_content = path.read_text()
|
||||
file_content = module_file.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 insert_import_error(path: Path):
|
||||
file_content = path.read_text().splitlines()
|
||||
file_content.insert(0, 'raise ImportError')
|
||||
path.write_text('\n'.join(file_content))
|
||||
|
||||
|
||||
def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
|
||||
assert isinstance(ad, AppDaemon)
|
||||
|
||||
module_file = Path(food.menu.__file__)
|
||||
modify_file(module_file)
|
||||
module_file.write_text(modified_content)
|
||||
|
||||
try:
|
||||
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):
|
||||
@@ -53,10 +41,11 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo
|
||||
|
||||
|
||||
def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
|
||||
assert isinstance(ad, AppDaemon)
|
||||
|
||||
module_file = Path(food.menu.__file__)
|
||||
insert_import_error(module_file)
|
||||
|
||||
file_content = module_file.read_text().splitlines()
|
||||
file_content.insert(0, 'raise ImportError')
|
||||
module_file.write_text('\n'.join(file_content))
|
||||
|
||||
try:
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import asyncio
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
from appdaemon.appdaemon import AppDaemon
|
||||
from git import Repo
|
||||
|
||||
|
||||
async def delayed_stop(ad: AppDaemon, delay: float):
|
||||
@@ -39,3 +41,9 @@ def get_loaded_apps(caplog: pytest.LogCaptureFixture):
|
||||
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)
|
||||
|
||||
|
||||
def reset_file(repo: Repo, changed: Path):
|
||||
if not changed.is_absolute():
|
||||
changed = Path(repo.working_tree_dir) / changed
|
||||
repo.git.checkout('HEAD', '--', changed)
|
||||
|
||||
Reference in New Issue
Block a user