#!/usr/bin/env python
"""
Test runner for LiuYao prompt tests.
Run this script to execute all LiuYao prompt preparation tests with detailed output.
"""

import os
import sys
import django
from django.test.utils import get_runner
from django.conf import settings

# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'iching.settings')
django.setup()

def run_liuyao_prompt_tests():
    """Run LiuYao prompt tests with detailed output."""
    from django.test.utils import get_runner
    from django.conf import settings
    
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=2, interactive=False, keepdb=True)
    
    # Run only the LiuYao prompt tests
    failures = test_runner.run_tests(['ai.tests.test_liuyao_prompt'])
    
    if failures:
        print(f"\n❌ {failures} test(s) failed")
        return False
    else:
        print("\n✅ All LiuYao prompt tests passed!")
        return True

def run_specific_test(test_name):
    """Run a specific test by name."""
    from django.test.utils import get_runner
    from django.conf import settings
    
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=2, interactive=False, keepdb=True)
    
    test_path = f'ai.tests.test_liuyao_prompt.LiuYaoPromptTestCase.{test_name}'
    failures = test_runner.run_tests([test_path])
    
    if failures:
        print(f"\n❌ Test {test_name} failed")
        return False
    else:
        print(f"\n✅ Test {test_name} passed!")
        return True

if __name__ == '__main__':
    print("🧪 Running LiuYao Prompt Tests...")
    print("=" * 50)
    
    if len(sys.argv) > 1:
        # Run specific test
        test_name = sys.argv[1]
        success = run_specific_test(test_name)
    else:
        # Run all tests
        success = run_liuyao_prompt_tests()
    
    if success:
        print("\n🎉 Testing completed successfully!")
        sys.exit(0)
    else:
        print("\n💥 Testing failed!")
        sys.exit(1) 