1+ #!/usr/bin/env python3
2+ """
3+ Test runner script for the LLM AOT Process project.
4+
5+ This script provides convenient ways to run different types of tests:
6+ - Unit tests (default)
7+ - Integration tests (requires API keys)
8+ - All tests
9+ - Specific test modules or functions
10+
11+ Usage:
12+ python run_tests.py # Run unit tests only
13+ python run_tests.py --integration # Run integration tests only
14+ python run_tests.py --all # Run all tests
15+ python run_tests.py --hybrid # Run hybrid-related tests only
16+ python run_tests.py --verbose # Run with verbose output
17+ python run_tests.py --coverage # Run with coverage report
18+ """
19+
20+ import sys
21+ import os
22+ import subprocess
23+ import argparse
24+ from pathlib import Path
25+
26+ def run_command (cmd , description = "" ):
27+ """Run a command and return success status"""
28+ print (f"🔄 { description } " )
29+ print (f"Running: { ' ' .join (cmd )} " )
30+ result = subprocess .run (cmd , capture_output = False )
31+ if result .returncode == 0 :
32+ print (f"✅ { description } - SUCCESS" )
33+ else :
34+ print (f"❌ { description } - FAILED" )
35+ return result .returncode == 0
36+
37+ def main ():
38+ parser = argparse .ArgumentParser (description = "Run tests for LLM AOT Process project" )
39+ parser .add_argument ("--integration" , action = "store_true" ,
40+ help = "Run integration tests (requires OPENROUTER_API_KEY)" )
41+ parser .add_argument ("--all" , action = "store_true" ,
42+ help = "Run all tests including integration tests" )
43+ parser .add_argument ("--hybrid" , action = "store_true" ,
44+ help = "Run hybrid-related tests only" )
45+ parser .add_argument ("--functionality" , action = "store_true" ,
46+ help = "Run functionality tests that catch method signature issues" )
47+ parser .add_argument ("--verbose" , "-v" , action = "store_true" ,
48+ help = "Run with verbose output" )
49+ parser .add_argument ("--coverage" , action = "store_true" ,
50+ help = "Run with coverage report" )
51+ parser .add_argument ("--module" , type = str ,
52+ help = "Run specific test module (e.g., 'tests.hybrid.test_hybrid_processor')" )
53+ parser .add_argument ("--function" , type = str ,
54+ help = "Run specific test function (e.g., 'test_hybrid_processor_method_signatures')" )
55+
56+ args = parser .parse_args ()
57+
58+ # Base pytest command - use sys.executable to ensure we use the right Python
59+ cmd = [sys .executable , "-m" , "pytest" ]
60+
61+ # Add verbosity
62+ if args .verbose :
63+ cmd .append ("-v" )
64+
65+ # Add coverage
66+ if args .coverage :
67+ cmd .extend (["--cov=src" , "--cov-report=html" , "--cov-report=term-missing" ])
68+
69+ # Determine what tests to run
70+ if args .all :
71+ cmd .append ("-m" )
72+ cmd .append ("integration or not integration" )
73+ description = "Running ALL tests (unit + integration)"
74+ elif args .integration :
75+ cmd .append ("-m" )
76+ cmd .append ("integration" )
77+ description = "Running INTEGRATION tests only"
78+ # Check for API key
79+ if not os .getenv ('OPENROUTER_API_KEY' ):
80+ print ("⚠️ WARNING: OPENROUTER_API_KEY environment variable not set" )
81+ print (" Integration tests may be skipped or fail" )
82+ elif args .hybrid :
83+ cmd .append ("tests/hybrid/" )
84+ if args .functionality :
85+ cmd .append ("tests/hybrid/test_hybrid_functionality.py" )
86+ description = "Running HYBRID tests only"
87+ elif args .functionality :
88+ cmd .append ("tests/hybrid/test_hybrid_method_signatures.py" )
89+ description = "Running FUNCTIONALITY tests (method signature validation)"
90+ elif args .module :
91+ cmd .append (args .module .replace ("." , "/" ) + ".py" )
92+ description = f"Running module: { args .module } "
93+ elif args .function :
94+ cmd .append ("-k" )
95+ cmd .append (args .function )
96+ description = f"Running function: { args .function } "
97+ else :
98+ # Default: run unit tests only (integration tests excluded by pytest.ini)
99+ description = "Running UNIT tests only (integration tests excluded)"
100+
101+ # Run the tests
102+ success = run_command (cmd , description )
103+
104+ if not success :
105+ print ("\n ❌ Tests failed!" )
106+ sys .exit (1 )
107+ else :
108+ print ("\n ✅ All tests passed!" )
109+
110+ # If running integration tests, provide helpful info
111+ if args .integration or args .all :
112+ print ("\n 📋 Integration Test Info:" )
113+ print (" - These tests make real API calls to OpenRouter" )
114+ print (" - They test end-to-end functionality with actual models" )
115+ print (" - Requires OPENROUTER_API_KEY environment variable" )
116+ print (" - Tests use: deepseek/deepseek-r1-0528:free and openrouter/cypher-alpha:free" )
117+
118+ if __name__ == "__main__" :
119+ main ()
0 commit comments