""" Test script for process() function Tests with various titles to validate the title processor """ from title_processor import process # Test cases TEST_CASES = [ # Comic style test cases { "test_id": "comic_discovery", "input_data": { "title": "Amazing Discovery in Science!", "subtitle": "Breakthrough research findings that will change everything", "primary_color": "#E74C3C", "background_color": "#FFFFFF" }, "style": "Comics", "max_width": 800 }, { "test_id": "comic_fun_facts", "input_data": { "title": "10 Fun Facts About Space Exploration", "subtitle": "Cool things you didn't know about the cosmos", "primary_color": "#3498DB", "background_color": "#F0F0F0" }, "style": "Comics", "max_width": 700 }, # Non-comic style test cases { "test_id": "professional_economy", "input_data": { "title": "Global Economic Growth Forecast for 2025", "subtitle": "Analysis of GDP trends across major economies", "primary_color": "#2E7D32", "background_color": "#FFFFFF" }, "style": "professional", "max_width": 900 }, { "test_id": "europe_cars", "input_data": { "title": "Europe's Best-Selling Car Brands in H1 2025", "subtitle": "This visualization shows the best-selling car brands in Europe", "primary_color": "#1E5BBD", "background_color": "#E8E8E8" }, "style": "normal", "max_width": 850 }, { "test_id": "quality_life", "input_data": { "title": "How Quality of Life Has Changed in 30 Countries", "subtitle": "Citizens' perceptions of changes in their country's quality of life", "primary_color": "#E74C3C", "background_color": "#F5F5F5" }, "style": "normal", "max_width": 900 }, { "test_id": "carbon_emissions", "input_data": { "title": "Global Carbon Emissions by Sector", "subtitle": "Breaking down CO2 emissions from energy, transportation, industry, and agriculture", "primary_color": "#27AE60", "background_color": "#FFFFFF" }, "style": "professional", "max_width": 800 }, { "test_id": "tech_companies", "input_data": { "title": "America's Largest Technology Companies", "subtitle": "Market capitalization comparison of leading tech firms", "primary_color": "#8E44AD", "background_color": "#F5F5F5" }, "style": "normal", "max_width": 850 }, { "test_id": "renewable_energy", "input_data": { "title": "Renewable Energy Share of Total Electricity Generation", "subtitle": "Tracking solar, wind, hydro, and other renewable sources by country", "primary_color": "#16A085", "background_color": "#ECF0F1" }, "style": "professional", "max_width": 900 }, ] def test_single_case(test_case): """ Test process() function for a single case Args: test_case: Dictionary containing test_id, input_data, style, max_width Returns: True if successful, False otherwise """ test_id = test_case['test_id'] input_data = test_case['input_data'] style = test_case['style'] max_width = test_case['max_width'] output_file = f"output/{test_id}_process_test.svg" print(f"\n{'='*70}") print(f"TEST: {test_id}") print(f"{'='*70}") print(f"Title: {input_data['title']}") print(f"Style: {style}") print(f"Max Width: {max_width}px") print(f"{'='*70}") try: svg_content = process( input_data=input_data, output=output_file, max_width=max_width, text_align="center", show_sub_title=True, style=style ) if svg_content: print(f"✅ Success: SVG generated ({len(svg_content)} chars)") return True else: print(f"❌ Failed: process() returned None") return False except Exception as e: print(f"❌ Error: {e}") import traceback traceback.print_exc() return False if __name__ == "__main__": print("=" * 70) print("PROCESS() FUNCTION TEST") print(f"Testing {len(TEST_CASES)} cases") print("=" * 70) success_count = 0 failed_count = 0 for i, test_case in enumerate(TEST_CASES, 1): print(f"\n[{i}/{len(TEST_CASES)}]") success = test_single_case(test_case) if success: success_count += 1 else: failed_count += 1 # Summary print("\n" + "=" * 70) print("TEST SUMMARY") print("=" * 70) print(f"Total test cases: {len(TEST_CASES)}") print(f"✅ Successful: {success_count}") print(f"❌ Failed: {failed_count}") print(f"Success rate: {success_count/len(TEST_CASES)*100:.1f}%") print("=" * 70) if success_count == len(TEST_CASES): print("\n🎉 All tests passed!") elif success_count > 0: print(f"\n⚠️ {failed_count} test(s) failed") else: print("\n❌ All tests failed") print("\n" + "=" * 70)