Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-25 08:29:13

0001 #!/usr/bin/env python3
0002 """Run tests for swf-testbed repository."""
0003 import os
0004 import sys
0005 import subprocess
0006 from pathlib import Path
0007 
0008 def print_separator():
0009     """Print the 100-character separator line."""
0010     print("\n" + "*" * 100 + "\n")
0011 
0012 def main():
0013     """Main function."""
0014     print_separator()
0015     
0016     # Get the directory of this script
0017     script_dir = Path(__file__).resolve().parent
0018     
0019     # Check if we're in a virtual environment
0020     venv_path = script_dir / ".venv"
0021     if "VIRTUAL_ENV" not in os.environ:
0022         if venv_path.exists():
0023             print("🔧 Auto-activating virtual environment...")
0024             # Use the venv's Python for pytest
0025             venv_python = venv_path / "bin" / "python"
0026             if venv_python.exists():
0027                 os.environ["VIRTUAL_ENV"] = str(venv_path)
0028                 os.environ["PATH"] = f"{venv_path}/bin:{os.environ['PATH']}"
0029                 sys.executable = str(venv_python)
0030         else:
0031             print("❌ Error: No Python virtual environment found")
0032             print("   Please ensure .venv exists in the swf-testbed directory")
0033             print("   You can create it with: python3 -m venv .venv")
0034             return 1
0035     
0036     print(f"Using Python environment: {os.environ.get('VIRTUAL_ENV', 'system')}")
0037     
0038     # Check if tests directory exists and has content
0039     tests_dir = script_dir / "tests"
0040     if tests_dir.exists() and list(tests_dir.iterdir()):
0041         print("Running pytest for swf-testbed...")
0042         
0043         # Run pytest using regular subprocess
0044         result = subprocess.run([sys.executable, "-m", "pytest", "tests"], cwd=script_dir)
0045         return result.returncode
0046     else:
0047         print("[SKIP] No tests/ directory found in swf-testbed. Skipping.")
0048         return 0
0049 
0050 if __name__ == "__main__":
0051     sys.exit(main())