File indexing completed on 2026-04-25 08:29:13
0001
0002 """Run tests across all swf-* repositories."""
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 activate_venv():
0013 """Activate virtual environment if needed."""
0014 venv_path = Path(__file__).parent / ".venv"
0015 if "VIRTUAL_ENV" not in os.environ and venv_path.exists():
0016 print("🔧 Auto-activating virtual environment...")
0017
0018 venv_python = venv_path / "bin" / "python"
0019 if venv_python.exists():
0020 os.environ["VIRTUAL_ENV"] = str(venv_path)
0021 os.environ["PATH"] = f"{venv_path}/bin:{os.environ['PATH']}"
0022
0023 sys.executable = str(venv_python)
0024 else:
0025
0026 if not venv_path.exists():
0027 print("🔧 No virtual environment found, using system Python3...")
0028 sys.executable = "/usr/bin/python3"
0029
0030 def find_swf_repos(parent_dir):
0031 """Find all swf-* repositories in parent directory."""
0032 repos = []
0033 for item in sorted(Path(parent_dir).iterdir()):
0034 if item.is_dir() and item.name.startswith("swf-"):
0035 repos.append(item)
0036 return repos
0037
0038 def run_tests_for_repo(repo_path):
0039 """Run tests for a single repository."""
0040 repo_name = repo_path.name
0041 print(f"--- Running tests for {repo_name} ---")
0042
0043 test_script = repo_path / "run_tests.py"
0044
0045 if test_script.exists() and os.access(test_script, os.X_OK):
0046
0047 if repo_name == "swf-testbed" and repo_path == Path(__file__).parent:
0048 print("Running swf-testbed tests (preventing recursion)...")
0049
0050 import importlib.util
0051 spec = importlib.util.spec_from_file_location("run_tests", test_script)
0052 module = importlib.util.module_from_spec(spec)
0053 spec.loader.exec_module(module)
0054 return module.main() == 0
0055 else:
0056
0057 env = os.environ.copy()
0058 env["SWF_PARENT_DIR"] = str(repo_path.parent)
0059 result = subprocess.run([sys.executable, str(test_script)], cwd=repo_path, env=env)
0060 return result.returncode == 0
0061 else:
0062 print(f"[SKIP] No run_tests.py found for {repo_name}. Skipping.")
0063 return True
0064
0065 def main():
0066 """Main function."""
0067 print_separator()
0068
0069
0070 script_dir = Path(__file__).resolve().parent
0071 swf_parent_dir = script_dir.parent
0072
0073
0074 activate_venv()
0075
0076
0077 repos = find_swf_repos(swf_parent_dir)
0078 print(f"Found {len(repos)} swf-* repositories in {swf_parent_dir}")
0079
0080 all_passed = True
0081
0082 for repo in repos:
0083 success = run_tests_for_repo(repo)
0084 if not success:
0085 all_passed = False
0086 print(f"--- Finished {repo.name} ---")
0087
0088 if all_passed:
0089 print("--- All tests completed successfully ---")
0090 return 0
0091 else:
0092 print("--- Some tests failed ---")
0093 return 1
0094
0095 if __name__ == "__main__":
0096 sys.exit(main())