#!/bin/bash

# Run Python unit tests for pywasot

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON_DIR="$(dirname "$SCRIPT_DIR")"
PROJECT_ROOT="$(dirname "$PYTHON_DIR")"
VENV_DIR="$PROJECT_ROOT/.venv"

echo "Running pywasot Python tests"
echo "============================="
echo ""

# Check if venv exists
if [[ ! -d "$VENV_DIR" ]]; then
    echo "Error: Python venv not found at $VENV_DIR"
    echo "Run 'uv sync' from project root first."
    exit 1
fi

# Source the venv
source "$VENV_DIR/bin/activate"

# Check if pytest is installed
if ! python -c "import pytest" 2>/dev/null; then
    echo "Installing pytest..."
    python -m pip install pytest -q
fi

# Run tests
cd "$PYTHON_DIR"
python -m pytest tests/unit/test_python_wrappers.py -v "$@"

echo ""
echo "Python tests completed!"
