#!/usr/bin/env python3 """Test script for timeout fixes""" import asyncio import logging import sys from pathlib import Path # Add src to path sys.path.insert(0, str(Path(__file__).parent / 'src')) from src.connector import Config, OpenAIEditClient, ImageEditRequest # Setup logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) logger = logging.getLogger(__name__) async def test_image_edit(): """Test image editing with new timeout settings""" try: # Initialize config config = Config() logger.info(f"Timeout setting: {config.default_timeout}s") logger.info(f"Max image size: {config.max_image_size_mb}MB") # Find test image input_path = config.input_path / "imagen4.png" if not input_path.exists(): logger.error(f"Test image not found: {input_path}") return False # Check original size original_size = input_path.stat().st_size / (1024 * 1024) logger.info(f"Original image size: {original_size:.2f}MB") # Create client client = OpenAIEditClient(config) # Create edit request request = ImageEditRequest( image_path=str(input_path), prompt="Add magical sparkles around the fairy", background="transparent", auto_optimize=True ) logger.info("Starting edit request...") start_time = asyncio.get_event_loop().time() # Process edit response = await client.edit_image(request) end_time = asyncio.get_event_loop().time() total_time = end_time - start_time if response.success: logger.info(f"✅ Edit successful in {total_time:.1f}s") logger.info(f"Output size: {response.image_size}") # Save result output_path = config.generated_images_path / "test_timeout_fix.png" if output_path.parent.exists(): with open(output_path, 'wb') as f: f.write(response.edited_image_data) logger.info(f"Saved to: {output_path}") return True else: logger.error(f"❌ Edit failed: {response.error_message}") logger.error(f"Error type: {response.error_type}") return False except Exception as e: logger.error(f"Test failed with exception: {e}") return False if __name__ == "__main__": # Run test success = asyncio.run(test_image_edit()) sys.exit(0 if success else 1)