#!/usr/bin/env python3 """ Test runner script for the journal organizer project. Provides easy access to run different types of tests. """ import sys import subprocess from pathlib import Path def run_command(cmd, description): """Run a command and handle the result""" print(f"\n{'='*60}") print(f"Running: {description}") print(f"Command: {' '.join(cmd)}") print('='*60) try: result = subprocess.run(cmd, check=True, capture_output=False) print(f"\nāœ… {description} - PASSED") return True except subprocess.CalledProcessError as e: print(f"\nāŒ {description} - FAILED (exit code: {e.returncode})") return False def main(): """Main test runner""" if len(sys.argv) < 2: print("Usage: python run_tests.py [unit|integration|all|coverage]") print("\nOptions:") print(" unit - Run unit tests only") print(" integration - Run integration tests only (may have import issues)") print(" all - Run all tests") print(" coverage - Run tests with coverage report") print(" help - Show this help message") return test_type = sys.argv[1].lower() if test_type == "help": main() return # Base pytest command base_cmd = ["python", "-m", "pytest", "-v"] success = True if test_type == "unit": cmd = base_cmd + ["tests/unit/"] success = run_command(cmd, "Unit Tests") elif test_type == "integration": cmd = base_cmd + ["tests/integration/"] success = run_command(cmd, "Integration Tests") elif test_type == "all": # Run unit tests first cmd = base_cmd + ["tests/unit/"] success = run_command(cmd, "Unit Tests") if success: # Run integration tests cmd = base_cmd + ["tests/integration/"] success = run_command(cmd, "Integration Tests") and success elif test_type == "coverage": cmd = base_cmd + ["--cov=.", "--cov-report=term-missing", "--cov-report=html:htmlcov", "tests/unit/"] success = run_command(cmd, "Unit Tests with Coverage") if success: print(f"\nšŸ“Š Coverage report generated in htmlcov/index.html") else: print(f"Unknown test type: {test_type}") print("Use 'python run_tests.py help' for usage information") return # Summary print(f"\n{'='*60}") if success: print("šŸŽ‰ All tests completed successfully!") else: print("šŸ’„ Some tests failed. Check the output above for details.") print('='*60) if __name__ == "__main__": main()