adi-o3-multipass/test_multiplier_system.py

203 lines
No EOL
7.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Test script for the new multiplier-based extraction system.
Tests the expansion engine with sample base deliverables.
"""
import sys
import os
import json
from process_brief_enhanced import BaseDeliverable, expand_deliverables, MarketingAsset
def test_expansion_engine():
"""Test the expansion engine with various scenarios."""
print("=== Testing Multiplier-Based Expansion Engine ===\n")
# Test Case 1: Multiple specs, single market
print("Test Case 1: Multiple specs, single market")
base1 = BaseDeliverable(
title="Meta Static Sizes",
technical_specifications=["1080x1920", "1200x1500", "1080x1080"],
country="UK",
media="IMAGE",
asset_type="JPG",
quantity="3"
)
expanded1, warnings1 = expand_deliverables([base1])
print(f"Input: 1 base deliverable with 3 specs")
print(f"Output: {len(expanded1)} individual deliverables")
print(f"Warnings: {len(warnings1)}")
if warnings1:
for warning in warnings1:
print(f" - {warning}")
print()
# Test Case 2: Multiple specs, multiple markets
print("Test Case 2: Multiple specs, multiple markets")
base2 = BaseDeliverable(
title="Display Banners",
technical_specifications=["160x600", "300x250", "728x90"],
country=["UK", "DE", "FR"],
media="IMAGE",
asset_type="JPG",
quantity="9"
)
expanded2, warnings2 = expand_deliverables([base2])
print(f"Input: 1 base deliverable with 3 specs × 3 markets")
print(f"Output: {len(expanded2)} individual deliverables")
print(f"Warnings: {len(warnings2)}")
if warnings2:
for warning in warnings2:
print(f" - {warning}")
print()
# Test Case 3: Copy with markets and types
print("Test Case 3: Copy with multiple markets and copy types")
base3 = BaseDeliverable(
title="Meta Copy",
technical_specifications=["Body Copy", "Headline", "Description"],
country=["UK", "DE", "FR", "ES", "IT"],
media="COPY",
asset_type="TEXT",
quantity="15"
)
expanded3, warnings3 = expand_deliverables([base3])
print(f"Input: 1 base deliverable with 3 copy types × 5 markets")
print(f"Output: {len(expanded3)} individual deliverables")
print(f"Warnings: {len(warnings3)}")
if warnings3:
for warning in warnings3:
print(f" - {warning}")
print()
# Test Case 4: Single values (no arrays)
print("Test Case 4: Single values (no multipliers)")
base4 = BaseDeliverable(
title="Single Video",
technical_specifications="1920x1080",
country="UK",
media="VIDEO",
asset_type="MP4",
quantity="1"
)
expanded4, warnings4 = expand_deliverables([base4])
print(f"Input: 1 base deliverable with no multipliers")
print(f"Output: {len(expanded4)} individual deliverables")
print(f"Warnings: {len(warnings4)}")
if warnings4:
for warning in warnings4:
print(f" - {warning}")
print()
# Test Case 5: Quantity mismatch (should generate warning)
print("Test Case 5: Quantity mismatch (should warn)")
base5 = BaseDeliverable(
title="Mismatch Test",
technical_specifications=["160x600", "300x250"],
country=["UK", "DE"],
media="IMAGE",
asset_type="JPG",
quantity="10" # Should be 4 (2×2), not 10
)
expanded5, warnings5 = expand_deliverables([base5])
print(f"Input: 1 base deliverable with 2 specs × 2 markets (expected 4), but quantity says 10")
print(f"Output: {len(expanded5)} individual deliverables")
print(f"Warnings: {len(warnings5)}")
if warnings5:
for warning in warnings5:
print(f" - {warning}")
print()
# Summary
total_base = 5
total_expanded = len(expanded1) + len(expanded2) + len(expanded3) + len(expanded4) + len(expanded5)
total_warnings = len(warnings1) + len(warnings2) + len(warnings3) + len(warnings4) + len(warnings5)
print("=== Test Summary ===")
print(f"Total base deliverables tested: {total_base}")
print(f"Total expanded deliverables created: {total_expanded}")
print(f"Total warnings generated: {total_warnings}")
# Expected: 3 + 9 + 15 + 1 + 4 = 32
expected_total = 32
print(f"Expected total deliverables: {expected_total}")
print(f"Test {'PASSED' if total_expanded == expected_total else 'FAILED'}!")
return total_expanded == expected_total
def test_sample_json_save():
"""Test saving base deliverables to JSON format."""
print("\n=== Testing JSON Serialization ===")
# Create sample base deliverables
base_deliverables = [
BaseDeliverable(
title="Display - Celtra Static Banners",
technical_specifications=["160x600", "300x250", "300x600", "728x90", "970x250", "320x50", "320x100", "336x280"],
country=["UK", "DE", "ES", "IT", "FR", "BE", "NL", "PL", "GR", "CZ", "SE", "DK", "PT", "CH", "SK", "RO", "HR", "FI", "NO", "AT"],
media="IMAGE",
asset_type="JPG",
quantity="160"
),
BaseDeliverable(
title="Meta Copy - Franchise",
technical_specifications=["Body Copy", "Headline", "Description"],
country=["UK", "DE", "FR", "ES", "IT", "NL", "PL", "SE", "DK", "NO", "FI", "IE", "GR", "PT", "BE", "CZ", "SK", "CH", "AT"],
media="COPY",
asset_type="TEXT",
quantity="57"
)
]
# Test JSON serialization
json_data = {
"timestamp": "20250903120000",
"document_type": "test",
"base_deliverables_count": len(base_deliverables),
"base_deliverables": [base.model_dump() for base in base_deliverables]
}
try:
json_str = json.dumps(json_data, indent=2, ensure_ascii=False)
print("JSON serialization: SUCCESS")
print(f"JSON size: {len(json_str)} characters")
# Show first base deliverable structure
print("\nSample base deliverable JSON structure:")
sample = json_data["base_deliverables"][0]
for key, value in sample.items():
if isinstance(value, list):
print(f" {key}: array with {len(value)} items")
else:
print(f" {key}: {value}")
except Exception as e:
print(f"JSON serialization: FAILED - {e}")
return False
return True
if __name__ == "__main__":
print("Multiplier-Based Extraction System - Test Suite")
print("=" * 60)
# Run tests
expansion_test_passed = test_expansion_engine()
json_test_passed = test_sample_json_save()
print(f"\n{'='*60}")
print("OVERALL TEST RESULTS:")
print(f"Expansion Engine: {'PASSED' if expansion_test_passed else 'FAILED'}")
print(f"JSON Serialization: {'PASSED' if json_test_passed else 'FAILED'}")
if expansion_test_passed and json_test_passed:
print("\n🎉 All tests PASSED! The new multiplier system is ready.")
sys.exit(0)
else:
print("\n❌ Some tests FAILED. Please check the implementation.")
sys.exit(1)