1+ #!/usr/bin/env python3
2+ """
3+ Test script to validate uvicorn upgrade requirements.
4+ Run this script to verify the dependency installation works.
5+ """
6+
7+ import subprocess
8+ import sys
9+ import tempfile
10+ import os
11+
12+ def test_requirements_installation ():
13+ """Test if the updated requirements can be installed successfully."""
14+ print ("Testing uvicorn upgrade requirements installation..." )
15+
16+ # Create a temporary virtual environment
17+ with tempfile .TemporaryDirectory () as temp_dir :
18+ venv_path = os .path .join (temp_dir , "test_venv" )
19+
20+ try :
21+ # Create virtual environment
22+ print ("Creating test virtual environment..." )
23+ subprocess .run ([sys .executable , "-m" , "venv" , venv_path ], check = True )
24+
25+ # Get pip path
26+ if os .name == "nt" : # Windows
27+ pip_path = os .path .join (venv_path , "Scripts" , "pip" )
28+ python_path = os .path .join (venv_path , "Scripts" , "python" )
29+ else : # Unix/Linux/Mac
30+ pip_path = os .path .join (venv_path , "bin" , "pip" )
31+ python_path = os .path .join (venv_path , "bin" , "python" )
32+
33+ # Upgrade pip
34+ print ("Upgrading pip..." )
35+ subprocess .run ([python_path , "-m" , "pip" , "install" , "--upgrade" , "pip" ],
36+ check = True , capture_output = True )
37+
38+ # Install requirements
39+ print ("Installing requirements..." )
40+ subprocess .run ([pip_path , "install" , "-r" , "src/requirements.txt" ],
41+ check = True , capture_output = True )
42+
43+ # Test import
44+ print ("Testing imports..." )
45+ result = subprocess .run ([
46+ python_path , "-c" ,
47+ "import fastapi; import uvicorn; import gunicorn; print('✓ All imports successful')"
48+ ], capture_output = True , text = True )
49+
50+ if result .returncode == 0 :
51+ print ("✓ Requirements installation test PASSED" )
52+ print (result .stdout )
53+ return True
54+ else :
55+ print ("✗ Import test failed:" )
56+ print (result .stderr )
57+ return False
58+
59+ except subprocess .CalledProcessError as e :
60+ print (f"✗ Installation failed: { e } " )
61+ return False
62+ except Exception as e :
63+ print (f"✗ Unexpected error: { e } " )
64+ return False
65+
66+ if __name__ == "__main__" :
67+ print ("=" * 50 )
68+ print ("Uvicorn Upgrade Requirements Test" )
69+ print ("=" * 50 )
70+
71+ success = test_requirements_installation ()
72+
73+ if success :
74+ print ("\n ✓ SUCCESS: Requirements can be installed without conflicts!" )
75+ sys .exit (0 )
76+ else :
77+ print ("\n ✗ FAILURE: Requirements installation failed!" )
78+ sys .exit (1 )
0 commit comments