mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-04 08:47:35 +08:00
- Create services/ package: asset_management, bulk_ingest, file_utils, hashing, ingest, metadata_extract, path_utils, schemas, tagging - Move business logic out of helpers.py into service modules - Remove manager.py and hashing.py (absorbed into services) - Add blake3 to requirements.txt - Add comprehensive service-layer tests Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019c9209-37af-757a-b6e4-af59b4267362
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.assets.database.models import Base
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def autoclean_unit_test_assets():
|
|
"""Override parent autouse fixture - service unit tests don't need server cleanup."""
|
|
yield
|
|
|
|
|
|
@pytest.fixture
|
|
def db_engine():
|
|
"""In-memory SQLite engine for fast unit tests."""
|
|
engine = create_engine("sqlite:///:memory:")
|
|
Base.metadata.create_all(engine)
|
|
return engine
|
|
|
|
|
|
@pytest.fixture
|
|
def session(db_engine):
|
|
"""Session fixture for tests that need direct DB access."""
|
|
with Session(db_engine) as sess:
|
|
yield sess
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_create_session(db_engine):
|
|
"""Patch create_session to use our in-memory database."""
|
|
from contextlib import contextmanager
|
|
from sqlalchemy.orm import Session as SASession
|
|
|
|
@contextmanager
|
|
def _create_session():
|
|
with SASession(db_engine) as sess:
|
|
yield sess
|
|
|
|
with patch("app.assets.services.ingest.create_session", _create_session), \
|
|
patch("app.assets.services.asset_management.create_session", _create_session), \
|
|
patch("app.assets.services.tagging.create_session", _create_session):
|
|
yield _create_session
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
"""Temporary directory for file operations."""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
yield Path(tmpdir)
|