File size: 2,695 Bytes
411a994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import sys
import importlib.util
import subprocess
import pytest
from colorama import init, Fore, Style

# Initialize colorama for colored output
init()

# Ensure project root is on sys.path
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
if PROJECT_ROOT not in sys.path:
    sys.path.insert(0, PROJECT_ROOT)

def check_dependencies():
    """Check if all required dependencies are installed"""
    required_packages = ['httpx', 'pytest', 'colorama', 'fastapi']
    missing_packages = []
    
    for package in required_packages:
        if importlib.util.find_spec(package) is None:
            missing_packages.append(package)
    
    if missing_packages:
        print(f"{Fore.RED}Missing required dependencies: {', '.join(missing_packages)}{Style.RESET_ALL}")
        install = input(f"Would you like to install them now? (y/n): ").lower().strip() == 'y'
        
        if install:
            print(f"{Fore.YELLOW}Installing missing packages...{Style.RESET_ALL}")
            subprocess.check_call([sys.executable, "-m", "pip", "install"] + missing_packages)
            print(f"{Fore.GREEN}Dependencies installed successfully!{Style.RESET_ALL}")
            return True
        else:
            print(f"{Fore.RED}Cannot run tests without required dependencies.{Style.RESET_ALL}")
            return False
    return True

def main():
    # Check dependencies first
    if not check_dependencies():
        return 1
        
    print(f"{Fore.CYAN}===== Running Unified API Tests ====={Style.RESET_ALL}")
    
    # Define test patterns to run
    test_patterns = [
        "tests/test_api_endpoints.py::test_unified_chat_text",
        "tests/test_live_ai.py::test_unified_text_live"
    ]
    
    # Run each test and collect results
    results = {}
    for pattern in test_patterns:
        print(f"\n{Fore.YELLOW}Running: {pattern}{Style.RESET_ALL}")
        exit_code = pytest.main([pattern, "-v"])
        results[pattern] = exit_code == 0
    
    # Print summary
    print(f"\n{Fore.CYAN}===== Test Results Summary ====={Style.RESET_ALL}")
    all_passed = True
    for pattern, passed in results.items():
        status = f"{Fore.GREEN}PASSED{Style.RESET_ALL}" if passed else f"{Fore.RED}FAILED{Style.RESET_ALL}"
        print(f"{pattern}: {status}")
        if not passed:
            all_passed = False
    
    # Final status
    if all_passed:
        print(f"\n{Fore.GREEN}All unified tests passed!{Style.RESET_ALL}")
    else:
        print(f"\n{Fore.RED}Some unified tests failed. Check the output above for details.{Style.RESET_ALL}")
    
    return 0 if all_passed else 1

if __name__ == "__main__":
    sys.exit(main())