|
|
|
|
|
|
|
|
|
|
|
|
|
import logging |
|
import shutil |
|
from pathlib import Path |
|
|
|
import pytest |
|
|
|
from invokeai.app.services.board_image_records.board_image_records_sqlite import SqliteBoardImageRecordStorage |
|
from invokeai.app.services.board_records.board_records_sqlite import SqliteBoardRecordStorage |
|
from invokeai.app.services.bulk_download.bulk_download_default import BulkDownloadService |
|
from invokeai.app.services.config.config_default import InvokeAIAppConfig |
|
from invokeai.app.services.images.images_default import ImageService |
|
from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCache |
|
from invokeai.app.services.invocation_services import InvocationServices |
|
from invokeai.app.services.invocation_stats.invocation_stats_default import InvocationStatsService |
|
from invokeai.app.services.invoker import Invoker |
|
from invokeai.backend.util.logging import InvokeAILogger |
|
from tests.backend.model_manager.model_manager_fixtures import * |
|
from tests.fixtures.sqlite_database import create_mock_sqlite_database |
|
from tests.test_nodes import TestEventService |
|
|
|
|
|
@pytest.fixture |
|
def mock_services() -> InvocationServices: |
|
configuration = InvokeAIAppConfig(use_memory_db=True, node_cache_size=0) |
|
logger = InvokeAILogger.get_logger() |
|
db = create_mock_sqlite_database(configuration, logger) |
|
|
|
|
|
return InvocationServices( |
|
board_image_records=SqliteBoardImageRecordStorage(db=db), |
|
board_images=None, |
|
board_records=SqliteBoardRecordStorage(db=db), |
|
boards=None, |
|
bulk_download=BulkDownloadService(), |
|
configuration=configuration, |
|
events=TestEventService(), |
|
image_files=None, |
|
image_records=None, |
|
images=ImageService(), |
|
invocation_cache=MemoryInvocationCache(max_cache_size=0), |
|
logger=logging, |
|
model_images=None, |
|
model_manager=None, |
|
download_queue=None, |
|
names=None, |
|
performance_statistics=InvocationStatsService(), |
|
session_processor=None, |
|
session_queue=None, |
|
urls=None, |
|
workflow_records=None, |
|
tensors=None, |
|
conditioning=None, |
|
style_preset_records=None, |
|
style_preset_image_files=None, |
|
) |
|
|
|
|
|
@pytest.fixture() |
|
def mock_invoker(mock_services: InvocationServices) -> Invoker: |
|
return Invoker(services=mock_services) |
|
|
|
|
|
@pytest.fixture(scope="module") |
|
def invokeai_root_dir(tmp_path_factory) -> Path: |
|
root_template = Path(__file__).parent.resolve() / "backend/model_manager/data/invokeai_root" |
|
temp_dir: Path = tmp_path_factory.mktemp("data") / "invokeai_root" |
|
shutil.copytree(root_template, temp_dir) |
|
return temp_dir |
|
|