#!/usr/bin/env python3 """ Test runner for Personal Internet Cell API Runs all unit tests and generates coverage reports """ import unittest import sys import os import subprocess from pathlib import Path def run_unit_tests(): """Run all unit tests""" print("๐Ÿงช Running Personal Internet Cell Unit Tests") print("=" * 50) # Add the api directory to Python path api_dir = Path(__file__).parent.parent sys.path.insert(0, str(api_dir)) # Discover and run tests loader = unittest.TestLoader() start_dir = Path(__file__).parent suite = loader.discover(start_dir, pattern='test_*.py') runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) return result.wasSuccessful() def run_pytest_with_coverage(): """Run pytest with coverage reporting""" print("\n๐Ÿ“Š Running pytest with coverage...") api_dir = Path(__file__).parent.parent os.chdir(api_dir) cmd = [ 'python', '-m', 'pytest', 'tests/', '--cov=app', '--cov=scripts', '--cov-report=html:htmlcov', '--cov-report=term-missing', '--cov-report=xml', '-v' ] try: result = subprocess.run(cmd, check=True, capture_output=True, text=True) print(result.stdout) return True except subprocess.CalledProcessError as e: print(f"โŒ pytest failed: {e}") print(e.stdout) print(e.stderr) return False def main(): """Main test runner""" print("๐Ÿš€ Personal Internet Cell - Test Suite") print("=" * 50) # Run unit tests unit_success = run_unit_tests() # Run pytest with coverage pytest_success = run_pytest_with_coverage() # Summary print("\n" + "=" * 50) print("๐Ÿ“‹ Test Summary") print("=" * 50) if unit_success and pytest_success: print("โœ… All tests passed!") print("๐Ÿ“Š Coverage report generated in htmlcov/") return 0 else: print("โŒ Some tests failed!") return 1 if __name__ == '__main__': sys.exit(main())