File size: 2,751 Bytes
64f3974 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
#!/usr/bin/env python3
"""
Test runner script for the Daily Household Electricity Consumption Predictor.
This script runs all tests and provides a summary of results.
"""
import subprocess
import sys
import os
from pathlib import Path
def run_tests():
"""Run all tests and return the result."""
print("🧪 Running Daily Household Electricity Consumption Predictor Tests")
print("=" * 70)
# Change to project root directory
project_root = Path(__file__).parent
os.chdir(project_root)
# Run pytest with coverage
cmd = [
sys.executable,
"-m",
"pytest",
"--verbose",
"--tb=short",
"--cov=src",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml",
"tests/",
]
try:
result = subprocess.run(cmd, capture_output=False, text=True)
return result.returncode == 0
except Exception as e:
print(f"❌ Error running tests: {e}")
return False
def run_unit_tests():
"""Run only unit tests."""
print("🧪 Running Unit Tests")
print("=" * 40)
cmd = [
sys.executable,
"-m",
"pytest",
"--verbose",
"--tb=short",
"-m",
"unit",
"tests/",
]
try:
result = subprocess.run(cmd, capture_output=False, text=True)
return result.returncode == 0
except Exception as e:
print(f"❌ Error running unit tests: {e}")
return False
def run_integration_tests():
"""Run only integration tests."""
print("🧪 Running Integration Tests")
print("=" * 40)
cmd = [
sys.executable,
"-m",
"pytest",
"--verbose",
"--tb=short",
"-m",
"integration",
"tests/",
]
try:
result = subprocess.run(cmd, capture_output=False, text=True)
return result.returncode == 0
except Exception as e:
print(f"❌ Error running integration tests: {e}")
return False
def main():
"""Main function to run tests based on command line arguments."""
if len(sys.argv) > 1:
test_type = sys.argv[1].lower()
if test_type == "unit":
success = run_unit_tests()
elif test_type == "integration":
success = run_integration_tests()
else:
print(f"❌ Unknown test type: {test_type}")
print("Available options: unit, integration, all (default)")
return 1
else:
success = run_tests()
if success:
print("\n✅ All tests passed!")
return 0
else:
print("\n❌ Some tests failed!")
return 1
if __name__ == "__main__":
sys.exit(main())
|