|
|
|
|
|
""" |
|
|
Test runner script for the Marine Species Identification API. |
|
|
""" |
|
|
|
|
|
import subprocess |
|
|
import sys |
|
|
import os |
|
|
from pathlib import Path |
|
|
|
|
|
def run_pytest(): |
|
|
"""Run pytest tests.""" |
|
|
print("π§ͺ Running pytest tests...") |
|
|
try: |
|
|
result = subprocess.run([ |
|
|
sys.executable, "-m", "pytest", |
|
|
"tests/", |
|
|
"-v", |
|
|
"--tb=short" |
|
|
], check=True) |
|
|
print("β
All pytest tests passed!") |
|
|
return True |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"β Some pytest tests failed (exit code: {e.returncode})") |
|
|
return False |
|
|
except FileNotFoundError: |
|
|
print("β οΈ pytest not found, skipping pytest tests") |
|
|
return True |
|
|
|
|
|
def run_simple_test(): |
|
|
"""Run the simple API test.""" |
|
|
print("π§ͺ Running simple API test...") |
|
|
try: |
|
|
result = subprocess.run([ |
|
|
sys.executable, "test_api_simple.py" |
|
|
], check=True) |
|
|
print("β
Simple API test completed!") |
|
|
return True |
|
|
except subprocess.CalledProcessError as e: |
|
|
print(f"β Simple API test failed (exit code: {e.returncode})") |
|
|
return False |
|
|
|
|
|
def main(): |
|
|
"""Main test runner.""" |
|
|
print("π Marine Species Identification API - Test Runner") |
|
|
print("=" * 55) |
|
|
|
|
|
|
|
|
project_dir = Path(__file__).parent |
|
|
os.chdir(project_dir) |
|
|
|
|
|
success = True |
|
|
|
|
|
|
|
|
if not run_pytest(): |
|
|
success = False |
|
|
|
|
|
print() |
|
|
|
|
|
|
|
|
print("π Note: To run the simple API test, start the API first:") |
|
|
print(" python start_api.py") |
|
|
print(" # Then in another terminal:") |
|
|
print(" python test_api_simple.py") |
|
|
|
|
|
print("=" * 55) |
|
|
|
|
|
if success: |
|
|
print("π All available tests completed successfully!") |
|
|
return 0 |
|
|
else: |
|
|
print("β Some tests failed") |
|
|
return 1 |
|
|
|
|
|
if __name__ == "__main__": |
|
|
sys.exit(main()) |
|
|
|