#!/usr/bin/env python3 """ Test runner script for Calejo Control Adapter. This script provides different test execution options: - Run all tests - Run unit tests only - Run integration tests only - Run tests with coverage - Run tests with specific markers """ import subprocess import sys import os from typing import List, Optional def run_tests( test_type: str = "all", coverage: bool = False, markers: Optional[List[str]] = None, verbose: bool = False ) -> int: """ Run tests using pytest. Args: test_type: Type of tests to run ("all", "unit", "integration") coverage: Whether to run with coverage markers: List of pytest markers to filter by verbose: Whether to run in verbose mode Returns: Exit code from pytest """ # Base pytest command cmd = ["pytest"] # Add test type filters if test_type == "unit": cmd.extend(["tests/unit"]) elif test_type == "integration": cmd.extend(["tests/integration"]) else: cmd.extend(["tests"]) # Add coverage if requested if coverage: cmd.extend([ "--cov=src", "--cov-report=term-missing", "--cov-report=html", "--cov-fail-under=80" ]) # Add markers if specified if markers: for marker in markers: cmd.extend(["-m", marker]) # Add verbose flag if verbose: cmd.append("-v") # Add additional pytest options cmd.extend([ "--tb=short", "--strict-markers", "--strict-config" ]) print(f"Running tests with command: {' '.join(cmd)}") print("-" * 60) # Run pytest result = subprocess.run(cmd) return result.returncode def main(): """Main function to parse arguments and run tests.""" import argparse parser = argparse.ArgumentParser(description="Run Calejo Control Adapter tests") parser.add_argument( "--type", choices=["all", "unit", "integration"], default="all", help="Type of tests to run" ) parser.add_argument( "--coverage", action="store_true", help="Run with coverage reporting" ) parser.add_argument( "--marker", action="append", help="Run tests with specific markers (can be used multiple times)" ) parser.add_argument( "--verbose", "-v", action="store_true", help="Run in verbose mode" ) parser.add_argument( "--quick", action="store_true", help="Run quick tests only (unit tests without database)" ) args = parser.parse_args() # Handle quick mode if args.quick: args.type = "unit" if args.marker is None: args.marker = [] args.marker.append("not database") # Run tests exit_code = run_tests( test_type=args.type, coverage=args.coverage, markers=args.marker, verbose=args.verbose ) sys.exit(exit_code) if __name__ == "__main__": main()