Fix unit tests

This commit is contained in:
doctorpangloss 2025-10-24 10:51:18 -07:00
parent 4c67f75d36
commit df786c59ce
2 changed files with 14 additions and 6 deletions

View File

@ -102,7 +102,7 @@ class PathsList:
paths = [x for x in self] paths = [x for x in self]
return paths[item] return paths[item]
def append(self, path_str: str): def append(self, path_str: str | Path):
p: FolderNames = self.parent() p: FolderNames = self.parent()
p.add_paths(self.folder_name, [path_str]) p.add_paths(self.folder_name, [path_str])

View File

@ -1,22 +1,26 @@
import pytest
import base64 import base64
import json import json
import struct import struct
from io import BytesIO from io import BytesIO
import pytest
from PIL import Image from PIL import Image
from aiohttp import web from aiohttp import web
from unittest.mock import patch
from comfy.app.model_manager import ModelFileManager from comfy.app.model_manager import ModelFileManager
from comfy.component_model.folder_path_types import FolderNames
from comfy.execution_context import context_folder_names_and_paths
pytestmark = ( pytestmark = (
pytest.mark.asyncio pytest.mark.asyncio
) # This applies the asyncio mark to all test functions in the module ) # This applies the asyncio mark to all test functions in the module
@pytest.fixture @pytest.fixture
def model_manager(): def model_manager():
return ModelFileManager() return ModelFileManager()
@pytest.fixture @pytest.fixture
def app(model_manager): def app(model_manager):
app = web.Application() app = web.Application()
@ -25,6 +29,7 @@ def app(model_manager):
app.add_routes(routes) app.add_routes(routes)
return app return app
async def test_get_model_preview_safetensors(aiohttp_client, app, tmp_path): async def test_get_model_preview_safetensors(aiohttp_client, app, tmp_path):
img = Image.new('RGB', (100, 100), 'white') img = Image.new('RGB', (100, 100), 'white')
img_byte_arr = BytesIO() img_byte_arr = BytesIO()
@ -43,9 +48,12 @@ async def test_get_model_preview_safetensors(aiohttp_client, app, tmp_path):
f.write(length_bytes) f.write(length_bytes)
f.write(header_bytes) f.write(header_bytes)
with patch('folder_paths.folder_names_and_paths', { fn = FolderNames()
'test_folder': ([str(tmp_path)], None) with context_folder_names_and_paths(fn):
}): test_folder = fn["test_folder"]
test_folder.paths.append(tmp_path)
test_folder.supported_extensions |= {".safetensors"}
client = await aiohttp_client(app) client = await aiohttp_client(app)
response = await client.get('/experiment/models/preview/test_folder/0/test_model.safetensors') response = await client.get('/experiment/models/preview/test_folder/0/test_model.safetensors')