"""Pytest fixtures for mcp-image-gen tests.""" import base64 import io import sys from pathlib import Path import pytest # Make src/ importable sys.path.insert(0, str(Path(__file__).parent.parent / "src")) @pytest.fixture(autouse=True) def comfyui_url(monkeypatch): """Set COMFYUI_URL to a test URL for all tests.""" monkeypatch.setenv("COMFYUI_URL", "http://test-comfyui:8188") # Also patch the module-level constant in server import server monkeypatch.setattr(server, "COMFYUI_URL", "http://test-comfyui:8188") @pytest.fixture def sample_image_bytes(): """Generate a 1x1 red pixel PNG as bytes using Pillow.""" from PIL import Image img = Image.new("RGB", (1, 1), color=(255, 0, 0)) buf = io.BytesIO() img.save(buf, format="PNG") return buf.getvalue() @pytest.fixture def mock_history_response(): """Sample ComfyUI history response for prompt_id='test-uuid-1234'.""" return { "test-uuid-1234": { "outputs": { "9": { "images": [ { "filename": "mcp-image-gen_00001_.png", "subfolder": "", "type": "output", } ] } }, "status": {"completed": True}, } } @pytest.fixture def queue_empty(): """ComfyUI queue response with nothing running or pending.""" return {"queue_running": [], "queue_pending": []} @pytest.fixture def queue_with_pending(): """ComfyUI queue response with our test prompt pending.""" return { "queue_running": [], "queue_pending": [[1, "test-uuid-1234", {}, {}]], } @pytest.fixture def queue_with_running(): """ComfyUI queue response with our test prompt running.""" return { "queue_running": [[1, "test-uuid-1234", {}, {}]], "queue_pending": [], }